Bug Tracker

Modify

Ticket #2164 (closed feature: fixed)

Opened 5 years ago

Last modified 14 months ago

.first() and .last() methods?

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

Description

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).

Implementation:

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

Change History

comment:1 Changed 5 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 5 years ago by joern

  • Status changed from new to closed
  • Resolution set to invalid

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

comment:3 Changed 4 years ago by john

  • Status changed from closed to reopened
  • Version changed from 1.2.2 to 1.3.2
  • Resolution invalid deleted
  • Milestone changed from 1.2.3 to 1.3.3

comment:4 Changed 4 years ago by john

  • Status changed from reopened to closed
  • Resolution set to fixed

Landed in SVN rev [6541].

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.