Ticket #10970 (closed bug: fixed)
The .on() selector parameter doesn't work with :not(:first) selector
| Reported by: | ben.katz@… | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.7.2 |
| Component: | event | Version: | 1.7.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I'm using the .on() selector in this manner:
$(document).on("click", "#users_table tr", function (event) {
and it works. If I add the :not(:first) (which works in any other selector usage), the event is not triggered on all rows (instead of not triggering only on the first row)
$(document).on("click", "#users_table tr:not(:first)", function (event) {
Change History
comment:2 Changed 18 months ago by sindresorhus
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to event
Confirmed on latest Chrome/Firefox. Improved testcase
As a temporary workaround, you can use tr:get(0) instead.
You should also use delegating instead of live:
http://jsfiddle.net/mofle/4QqtR/
comment:3 Changed 18 months ago by dmethvin
Looks like two problems here. One is with the POS regexp in .is(), it isn't sending :first to the positional selector route. Then there seems to be a bug in Chrome where a selector with :first in it returns false rather than throwing, which is should since that's a non-standard selector.
However, using positional selectors in a case like that is a very bad idea because it is much less efficient than a standard selector. It has to select all the elements that apply and see if the one you are asking about is in that set.
You can use :first-child instead and it works.
comment:4 Changed 18 months ago by dmethvin
False alarm on the Chrome bug, it seems to be working fine. We're working on the regexp issue.
comment:6 Changed 18 months ago by timmywil
- Status changed from open to closed
- Resolution set to fixed
Use Sizzle.Expr.match.globalPOS for identifying POS selectors in traversing. Fixes #10970.
Changeset: 2a63b980eda1cf4ec1c2f27749821785c78c65b6
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

The working example on jsfiddle: http://jsfiddle.net/LMeFc/2/