Skip to main content

Bug Tracker

Side navigation

#10800 closed bug (wontfix)

Opened November 16, 2011 10:05AM UTC

Closed November 16, 2011 01:12PM UTC

Last modified November 17, 2011 08:46AM UTC

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:

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


Attachments (0)
Change History (2)

Changed November 16, 2011 01:12PM UTC by dmethvin comment:1

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.

Changed November 17, 2011 08:46AM UTC by anonymous comment:2

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 !