Skip to main content

Bug Tracker

Side navigation

#14100 closed bug (notabug)

Opened July 03, 2013 02:54PM UTC

Closed July 03, 2013 03:43PM UTC

Last modified September 16, 2013 01:21AM UTC

.has() method ignores child ( > ) selector

Reported by: goozak Owned by: timmywil
Priority: high Milestone: 1.11/2.1
Component: traversing Version: 1.10.1
Keywords: Cc:
Blocked by: Blocking:
Description

There is a difference between the .has() method and the :has() selector with regards to the child selector (>)

http://jsfiddle.net/wMBBc/

The .has() method seems to ignore the presence of the child selector (>).

Attachments (0)
Change History (8)

Changed July 03, 2013 03:16PM UTC by timmywil comment:1

component: unfiledtraversing
milestone: None1.10.3/2.0.4
owner: → timmywil
priority: undecidedhigh
status: newassigned

This is valid. .has() selects its targets then independently does a .contains() check. However, this is probably the only use case I can think of that would fail.

Changed July 03, 2013 03:23PM UTC by dmethvin comment:2

It seems consistent with the docs:

The supplied selector is tested against the **descendants** of the matching elements; the element will be included in the result if any of its descendant elements matches the selector. -- http://api.jquery.com/has/

One of the descendants of the outer td has a descendant with an input element as a child.

Also note that the selector string matching the .has() method case would be #rec td *:has(> input) and not the one you've used, since it's testing the descendants of the set and not the set elements themselves.

Does that make sense?

Changed July 03, 2013 03:43PM UTC by timmywil comment:3

resolution: → notabug
status: assignedclosed

@dmethvin:

You're right, forgive my confusion.

Changed July 03, 2013 04:06PM UTC by dmethvin comment:4

Now, does it make sense for these two cases to be different? Is the selector case wrong?

Changed July 03, 2013 05:20PM UTC by gibson042 comment:5

I stand behind the selector behavior, and would argue that our documentation text is sufficiently vague regarding implied scope to support either method implementation, though I personally prefer it to match the selector.

At any rate, this fix can be had for 15 min+gz bytes if we come down in favor of it.

Changed July 03, 2013 05:22PM UTC by timmywil comment:6

Continuing to work as documented seems fine with me. No change required. As Dave points out, it _does_ match the selector, just depends on which selector you're talking about.

Changed July 06, 2013 03:59PM UTC by goozak comment:7

Changed September 16, 2013 01:21AM UTC by dmethvin comment:8

milestone: 1.10.3/2.0.41.11/2.1

Bulk update for new milestone