Bug Tracker

Opened 15 years ago

Closed 14 years ago

Last modified 11 years ago

#2164 closed feature (fixed)

.first() and .last() methods?

Reported by: simonw Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc: simon+jquery@…
Blocked by: Blocking:


Is there any reason jQuery doesn't include methods for getting the .first() and .last() items in the current collection? I frequently use the :first and :last CSS selectors, so a method equivalent would be useful (and intuitive: I just had someone ask about a bug in their jQuery code caused by their assumption that .first() was a valid method).


jQuery.fn.first = function() { return this.eq(0) };
jQuery.fn.last = function() { return this.eq(this.size() - 1) };

Change History (4)

comment:1 Changed 15 years ago by flesler

this.eq(0) simply takes less bytes, why do you need another method. As for last(), you can do this.slice(-1), also pretty straightforward.

comment:2 Changed 15 years ago by joern

Resolution: invalid
Status: newclosed

Agree with Ariel. first/last were part of the API in earlier versions and not worth the effort.

comment:3 Changed 14 years ago by john

Resolution: invalid
Status: closedreopened

comment:4 Changed 14 years ago by john

Resolution: fixed
Status: reopenedclosed

Landed in SVN rev [6541].

Note: See TracTickets for help on using tickets.