Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13797 closed bug (fixed)

jQuery.fn.is returns incorrect result if used to check $(this) or $(e.currentTarget) and a positional pseudoselector is used

Reported by: [email protected] Owned by:
Priority: low Milestone: None
Component: traversing Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


This fiddle is the most reduced that shows the error: http://jsfiddle.net/garnwraly/sfrwU/21/

This fiddle shows why :first-child isn't suitable sometimes: http://jsfiddle.net/garnwraly/sfrwU/26/

This fiddle shows a workaround, apparently it works correctly if you pass a jQuery object into is instead of a selector. http://jsfiddle.net/XAKLP/

Change History (4)

comment:1 Changed 10 years ago by [email protected]

problem isolated by ryanbrill to be due to the context being set from document to the element is is being called from.

Can be worked around by writing $(e.currentTarget).parent().is.call(document, 'selector:first') instead of $(e.currentTarget).parent().is('selector:first')

Fiddle: http://jsfiddle.net/garnwraly/sfrwU/30/

Stackoverflow post: http://stackoverflow.com/a/16115841/482053

comment:2 Changed 10 years ago by Richard Gibson

Resolution: fixed
Status: newclosed

Fix #13797: .is with single-node context (cherry picked from commit 4f786ba4d2a5544cb48f589d2659d6cab84efc34)

Changeset: fb1731ab163424e22bac4372f15cda1195bfaa85

comment:3 Changed 10 years ago by gibson042

This ticket is now resolved, but I strongly recommend against sending positional selectors to .is. Please consider something with more obvious behavior, like using jQuery( positionalSelector ).is( e.currentTarget ) directly (reversing the context and argument).

comment:4 Changed 10 years ago by gibson042

Component: unfiledtraversing
Priority: undecidedlow
Note: See TracTickets for help on using tickets.