W3C home > Mailing lists > Public > public-webapi@w3.org > April 2008

Re: [SelectorsAPI] Thoughts on querySelectorAll

From: Jonas Sicking <jonas@sicking.cc>
Date: Wed, 30 Apr 2008 16:13:04 -0700
Message-ID: <4818FD00.1020101@sicking.cc>
To: John Resig <jresig@mozilla.com>
CC: "L. David Baron" <dbaron@dbaron.org>, public-webapi@w3.org

John Resig wrote:
>> There are two contrary statements in your proposal.
>> ":root" matches the root element (i.e. the "test" element in your
>> example)
>> All simple selectors has to match a descendant of the element on which
>> .querySelectorAll was called.
>> Clearly the "test" node isn't a descendant of itself, so the ":root" 
>> part couldn't match anything.
> That is correct - :root would be overloaded in this case (or simply called something else - like :scope). Isn't this how the combinator-leading selectors were proposed to work?
>   // Finding all child, div, elements
>   .querySelectorAll(":scope > div")
> Looking through the archives it appears as if that's what Maciej proposed. If that's not the case - and the :root/:scope points back to the document root (?) then please disregard all of this, as it's no longer useful.

The issue isn't what we define ":scope" to match in general. But rather 
that you are saying that only descendants of the "context node" are 
allowed to match the individual parts of the selector.

You are saying that for the selector .querySelectorAll("div span"), the 
"div" part and the "span" part both need to match a descendant of the 
context node. So while matching the implementation should only test 
descendants of the context node while matching the "div" part.

But you are also saying that for the selector
.querySelectorAll(":scope span") the "span" part needs to match a 
descendant of the context node, but the ":scope" part can match the 
context node itself. So here the implementation would have to test not 
just descendants of the context node, but also the context node itself.

What would a selector like ":link span" match? Can the ":link" part 
match the context node? I.e. will anything be returned for the following DOM

<a href="..." id="context"><b><span>hello</span></b></a>

What about "[foo] span", can the [foo] part match the context node?

<a href="..." foo="hi mom" id="context"><b><span>hello</span></b></a>

What about if the selector was ":scope[foo] span"? Would that selector 
return anything for the above DOM?

/ Jonas
Received on Wednesday, 30 April 2008 23:14:28 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:16:26 UTC