Modify ↓
Ticket #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: | ||
| Blocking: | Blocked by: |
Description
Hi,
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.
Regards.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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.