O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required