Bug Tracker

Opened 6 years ago

Closed 6 years ago

#14043 closed bug (notabug)

$('#root').find(':not(#nested) > li') fails

Reported by: ngryman Owned by: timmywil
Priority: high Milestone: None
Component: selector Version: 2.0.2
Keywords: Cc:
Blocked by: Blocking:

Description

This selector fails with the following html structure:

<ul id="root">
    <ul id="nested">
        <li></li>
    </ul>
    <li></li>
    <li></li>
</ul>

The QSA version works fine.

But if I change the container to a superior level (i.e. body) this works fine:

$('body').find(':not(#nested) > li')

It seems this selector does not work with direct children.

Here is a jsfiddle that illustrates the bug : http://jsfiddle.net/ngryman/tsw4b/. It fails for any version of jQuery.

Thanks.

Change History (5)

comment:1 Changed 6 years ago by gibson042

#14044 is a duplicate of this ticket.

comment:2 Changed 6 years ago by gibson042

Cc: timmywil added
Status: newopen

Confirmed. Sizzle's qSA path returns empty when it seems like it shouldn't be. The cause might be really obvious, but I'm just not seeing it—nor am I seeing a good way to catch it. Can someone else weigh in?

comment:3 Changed 6 years ago by ngryman

Oups sorry, I've posted it twice...

comment:4 Changed 6 years ago by timmywil

Cc: timmywil removed
Component: unfiledselector
Owner: set to timmywil
Priority: undecidedhigh
Status: openassigned

comment:5 Changed 6 years ago by timmywil

Resolution: notabug
Status: assignedclosed

This is not a bug. This is the scope issue with QSA being demonstrated. Sizzle's result is the correct one since #root should be the context.

Read the selector like this:

find children that are not #nested that contain any li's as direct descendants. #root does not have any children that are not #nested that contain lis. It only contains #nested and lis.

Note: See TracTickets for help on using tickets.