Getting DOM Objects from a jQuery Object Set

$("div").get();   //returns an array of DOM object for all <div> elements $("div").get(0);   //returns a DOM object for the first <div> $("div").get(-1);   //returns a DOM object for the last <div>

The .get([index]) method returns the DOM elements represented in the jQuery object set. If no index is specified, an array of the DOM objects is returned. If an index is specified, the DOM element at that zero-based offset in the array is returned.

If the index is a negative number, the item at the reverse offset from the end of the array is returned. For example, –1 is the last item and –2 is the second to the last item.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.