Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10800 closed bug (wontfix)

Delegation doesn't work well with :last selector

Reported by: anonymous Owned by:
Priority: low Milestone: None
Component: event Version: 1.7
Keywords: Cc:
Blocked by: Blocking:



This is my first post here.

There is a regression in jquery 1.7 when you use delegation such as $('tbody').delegate("tr:last", "change", function(e) {...}), if you have several tables on your page for example.

The same thing with the new 'on' event API.

You will find a use case here: http://jsfiddle.net/APyU7/2/

The event is triggered only on the last tr of the second table. It works with jquery 1.6.4.


Change History (2)

comment:1 Changed 11 years ago by dmethvin

Component: unfiledevent
Priority: undecidedlow
Resolution: wontfix
Status: newclosed

This is a regression, but it's due to fixing a bug and creating a consistent meaning for positional selectors like ":last", ":first", etc.

In 1.7 we have updated the docs to recommend against positional selectors because their meaning is ambiguous and they are very inefficient. We fixed a couple of bugs related to the way they work and this is a side-effect of that.

When you say $("tr:last") you are selecting the last tr on the page. The event delegation and .is(":last") now goes through the same code path so it also selects the last tr on the page. If you want the last tr in *each* table, use "tr:last-child" which is a standard W3C selector and in general is also much faster.

comment:2 Changed 11 years ago by anonymous

ok, I understand.

As the :last worked before, I never noticed such a subtlety. Going deeper in the documentation, I saw some comments on it. "tr:last-child" is exactly what I need.

Thanks for your help, your work, and for this great library !

Note: See TracTickets for help on using tickets.