Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#14100 closed bug (notabug)

.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 (>).

Change History (8)

comment:1 Changed 7 years ago by timmywil

Component: unfiledtraversing
Milestone: None1.10.3/2.0.4
Owner: set to 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.

comment:2 Changed 7 years ago by dmethvin

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?

comment:3 Changed 7 years ago by timmywil

Resolution: notabug
Status: assignedclosed

@dmethvin:

You're right, forgive my confusion.

comment:4 Changed 7 years ago by dmethvin

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

comment:5 Changed 7 years ago by gibson042

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.

comment:6 Changed 7 years ago by timmywil

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.

comment:8 Changed 7 years ago by dmethvin

Milestone: 1.10.3/2.0.41.11/2.1

Bulk update for new milestone

Note: See TracTickets for help on using tickets.