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 the First or Last Item

$("p").first(); //selects the first <p> elmemnt in the set $("p").last(); //selects the last <p> elmemnt in the set

The .first() method selects the first element in the jQuery object’s set. Many of the jQuery methods that return values end up using the first element in the set. The .last() method selects the last element in the jQuery object’s set.

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