Skip to main content

Bug Tracker

Side navigation

#10970 closed bug (fixed)

Opened December 07, 2011 09:36AM UTC

Closed December 12, 2011 04:24PM UTC

Last modified December 12, 2011 04:25PM UTC

The .on() selector parameter doesn't work with :not(:first) selector

Reported by: ben.katz@gmail.com Owned by:
Priority: low Milestone: 1.7.2
Component: event Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
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) {
Attachments (0)
Change History (7)

Changed December 07, 2011 09:40AM UTC by anonymous comment:1

The working example on jsfiddle:

http://jsfiddle.net/LMeFc/2/

Changed December 07, 2011 12:14PM UTC by sindresorhus comment:2

_comment0: Confirmed on latest Chrome/Firefox. [http://jsfiddle.net/mofle/xsACv/ Improved testcase] \ \ As a temporary workaround, you can use `tr:get(0)` instead.[[BR]] \ You should also use [http://api.jquery.com/on/#direct-and-delegated-events delegating] instead of live: \ http://jsfiddle.net/mofle/4QqtR/1323260081362077
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/

Changed December 07, 2011 03:11PM UTC by dmethvin comment:3

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.

Changed December 07, 2011 04:00PM UTC by dmethvin comment:4

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

Changed December 07, 2011 04:10PM UTC by timmywil comment:5

Dave and I discovered that we should origPOS here.

Changed December 12, 2011 04:24PM UTC by timmywil comment:6

resolution: → fixed
status: openclosed

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

Changeset: 2a63b980eda1cf4ec1c2f27749821785c78c65b6

Changed December 12, 2011 04:25PM UTC by timmywil comment:7

milestone: None1.7.2