Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7914 closed bug (duplicate)

.children() returns different result when passing a selector that uses ":first" in some cases

Reported by: patrickwhalen Owned by:
Priority: high Milestone: 1.next
Component: selector Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description

When passing a selector to $('#div2').children() in the form of [parent] > [child]...

  • if the :first selector is added to [parent],
  • and there are no immediate children that match [child],
  • but there is an immediate child that matches [parent],
  • and [parent] has an immediate child that matches [child]

... jQuery/Sizzle will return [parent].

http://jsfiddle.net/F62c3/

<div id='div2'>
    <ul id='ul2'>
        <li>4</li>
        <li>5</li>
        <li>6</li>
    </ul>
</div>
// Using "ul > li" selector returns an empty set (as it should)
$('#div2').children('ul > li'); 

// Using "ul:first > span" selector returns an empty set (as it should)
$('#div2').children('ul:first > span');

// Using "ul:first > li" selector returns the UL even though we're targeting LI
$('#div2').children('ul:first > li');

NOTE: The same applies to :last and :eq(0), but not :first/last/nth-child. I haven't tested beyond this.

Change History (4)

comment:1 Changed 8 years ago by patrickwhalen

This bug seems to have appeared in jQuery 1.4.3, and is the result of a fix where previous versions returned the [child] elements.

comment:2 Changed 8 years ago by jitter

Component: unfiledselector
Priority: undecidedhigh
Status: newopen

This looks valid and probably is a bug in Sizzle, this can be deduced from the fact that changing ul:first > li to ul:first-child > li yield different results (no-qSA vs. qSA use).

comment:3 Changed 8 years ago by john

Resolution: duplicate
Status: openclosed

We'll likely be fixing this in an upcoming Sizzle rewrite.

comment:4 Changed 8 years ago by john

Duplicate of #9810.

Note: See TracTickets for help on using tickets.