Bug Tracker

Ticket #10970 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

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:1 Changed 3 years ago by anonymous

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

comment:2 Changed 3 years 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:gt(0) instead.
You should also use  delegating instead of live:  http://jsfiddle.net/mofle/4QqtR/

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

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

Dave and I discovered that we should origPOS here.

comment:6 Changed 3 years 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

comment:7 Changed 3 years ago by timmywil

  • Milestone changed from None to 1.7.2
Note: See TracTickets for help on using tickets.