Bug Tracker

Opened 12 years ago

Closed 12 years ago

#4655 closed bug (invalid)

is function wrong with :first, :last, :last-child

Reported by: tigerf Owned by: john
Priority: major Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: is last first Cc:
Blocked by: Blocking:


I have some code that result is not match expectation.




 $('span:eq(0)').is('span:first') // yes, it is true
 $('span:eq(2)').is('span:first') // expect false but true

 $('span:eq(2)').is('span:last') // yes, it is true
 $('span:eq(0)').is('span:last') // expect false but true

 $('span:eq(0)').is('span:first-child') // yes, it is true
 $('span:eq(2)').is('span:first-child') // yes, it is false

 $('span:eq(2)').is('span:last-child') // expect true but false
 $('span:eq(0)').is('span:last-child') // yes, it is false

BTW: I don't know what is different between :first and :first-child.

Change History (1)

comment:1 Changed 12 years ago by dmethvin

Resolution: invalid
Status: newclosed

These are good things to explore with other users in a forum. Please don't file a bug report until you are sure it's a bug.

The .is() method takes its context from the collection of nodes it is given, similar to .filter(). (The docs note this relationship.) If the filter expression yields at least one element, .is() returns true.

Your examples are all selecting a single span, so :first and :last will be true. You aren't showing the complete markup, so I don't know whether the :*-child should return true or false.

Note: See TracTickets for help on using tickets.