SirRoland SirRoland - 1 year ago 52
jQuery Question

An array of elements in jQuery

Markup code:

<div id="elements">
<div>
<a href="#">text</a>
<a href="#">text</a>
<a href="#">text</a>
</div>
<div>
<a href="#">text</a>
<a href="#">text</a>
<a href="#">text</a>
</div>
<div>
<a href="#">text</a>
<a href="#">text</a>
</div>
</div>


Please tell me how can I get an array of all elements of the
div
, so that later, it is possible to address an array of options?

Such as:

divs[0]
links[1]

Answer Source

Demo

var divs = $('#elements div');
var links = $('#elements div a');
  1. If you want the DOM elements, then you can access them with the array style like divs[0] or links[2].
  2. If you want to get the specific jQuery object, you can access them with divs.eq(0) or links.eq(1).
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download