Modify ↓
Ticket #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: | ||
| Blocking: | Blocked by: |
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].
<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
comment:2 Changed 2 years ago by jitter
- Priority changed from undecided to high
- Status changed from new to open
- Component changed from unfiled to selector
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).
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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.