Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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:
Blocked by: Blocking:


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 (7)

comment:1 Changed 11 years ago by anonymous

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

comment:2 Changed 11 years ago by sindresorhus

Component: unfiledevent
Priority: undecidedlow
Status: newopen

Confirmed on latest Chrome/Firefox. Improved testcase

As a temporary workaround, you can use tr:gt(0) instead.
You should also use delegating instead of live: http://jsfiddle.net/mofle/4QqtR/

Last edited 11 years ago by sindresorhus (previous) (diff)

comment:3 Changed 11 years 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 11 years ago by dmethvin

False alarm on the Chrome bug, it seems to be working fine. We're working on the regexp issue.

comment:5 Changed 11 years ago by Timmy Willison

Dave and I discovered that we should origPOS here.

comment:6 Changed 11 years ago by Timmy Willison

Resolution: fixed
Status: openclosed

Use Sizzle.Expr.match.globalPOS for identifying POS selectors in traversing. Fixes #10970.

Changeset: 2a63b980eda1cf4ec1c2f27749821785c78c65b6

comment:7 Changed 11 years ago by Timmy Willison

Milestone: None1.7.2
Note: See TracTickets for help on using tickets.