Skip to main content

Bug Tracker

Side navigation

#13797 closed bug (fixed)

Opened April 20, 2013 01:49AM UTC

Closed April 20, 2013 03:53PM UTC

Last modified April 20, 2013 06:02PM UTC

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

Reported by: garnwraly@gmail.com 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/

Attachments (0)
Change History (4)

Changed April 20, 2013 02:59AM UTC by garnwraly@gmail.com comment:1

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

Changed April 20, 2013 03:53PM UTC by Richard Gibson comment:2

resolution: → fixed
status: newclosed

Fix #13797: .is with single-node context

(cherry picked from commit 4f786ba4d2a5544cb48f589d2659d6cab84efc34)

Changeset: fb1731ab163424e22bac4372f15cda1195bfaa85

Changed April 20, 2013 05:41PM UTC by gibson042 comment:3

This ticket is now resolved, but I [https://github.com/jquery/jquery/commit/fb1731ab163424e22bac4372f15cda1195bfaa85#commitcomment-3052968 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).

Changed April 20, 2013 06:02PM UTC by gibson042 comment:4

component: unfiledtraversing
priority: undecidedlow