#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: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | traversing | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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
comment:2 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fix #13797: .is with single-node context (cherry picked from commit 4f786ba4d2a5544cb48f589d2659d6cab84efc34)
Changeset: fb1731ab163424e22bac4372f15cda1195bfaa85
comment:3 Changed 10 years ago by
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
Component: | unfiled → traversing |
---|---|
Priority: | undecided → low |
problem isolated by ryanbrill to be due to the context being set from
document
to the elementis
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