Bug 17461 - querySelectorAll doesn't return correct nodes when using element in element patterns
Summary: querySelectorAll doesn't return correct nodes when using element in element p...
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: Nobody
: 17731 (view as bug list)
Depends on:
Reported: 2008-02-20 15:38 PST by Moxiecode Systems
Modified: 2008-03-09 08:14 PDT (History)
3 users (show)

See Also:

Testcase to illustrate the bug. (208 bytes, text/html)
2008-02-20 15:40 PST, Moxiecode Systems
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Moxiecode Systems 2008-02-20 15:38:27 PST
When using the querySelectorAll method on an element it doesn't return the correct number of nodes if a pattern with elements in elements are used.

For example if this code is executed on an element with 4 divs but only one div withing another div it should return 1 and not 4.

document.getElementById('test').querySelectorAll('div div');

<div id="test">
Comment 1 Moxiecode Systems 2008-02-20 15:40:28 PST
Created attachment 19242 [details]
Testcase to illustrate the bug.

This test case will alert 4 but should alert 1 since only one div is inside another div.
Comment 2 Anne van Kesteren 2008-02-20 15:53:18 PST
I'd mark this INVALID, but can't.

Anyway, selectors are always matched agains the document element. However, for calls on element nodes all nodes not part of the sub tree of that element node are filtered out. This is why you end up with 4 and not 1 or 5.
Comment 3 Anne van Kesteren 2008-02-20 15:56:13 PST
I shouild have mentioned that we will clarify the specification in due course to make this more explicit.
Comment 4 Adam Roben (:aroben) 2008-02-20 15:56:49 PST
Marking INVALID per Anne's comments.
Comment 5 Moxiecode Systems 2008-02-20 16:00:42 PST
Hmm, strange since this is not the way common libraries like jQuery/Prototype etc work. They all return 1 if you scope the search to an specific element so this can't be used as an replacement for those APIs. I could not find anything about this in the W3C specification so I'm wondering what is the correct behavior?
Comment 6 Sam Weinig 2008-03-09 08:14:31 PDT
*** Bug 17731 has been marked as a duplicate of this bug. ***