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

Re: [SelectorsAPI] Thoughts on querySelectorAll

From: Maciej Stachowiak <mjs@apple.com>
Date: Fri, 2 May 2008 18:44:16 -0700
Cc: John Resig <jresig@mozilla.com>, Lachlan Hunt <lachlan.hunt@lachy.id.au>, public-webapi@w3.org
Message-Id: <A5AAD0A8-2565-403B-B6C6-895EA9906683@apple.com>
To: Jonas Sicking <jonas@sicking.cc>


On May 2, 2008, at 5:35 PM, Jonas Sicking wrote:

>
> One alternative solution would be to say that the string ":scope "  
> is always prepended to the passed in selector. That would mean that  
> a selector like "div span" would be matched as ":scope div span"  
> where obviously the "div" and "span" parts can only match  
> descendants of the context node, and selection can never leak out  
> outside the context node. It would even make a selector like "> div"  
> work since it would be matched as ":scope > div" which is a valid  
> selector.

I proposed something similar on #whatwg today, that we add  
queryScopedSelector / queryScopedSelectorAll to elements, which has  
this behavior. See <http://krijnhoetmer.nl/irc-logs/whatwg/20080503#l-190 
 > for discussion.

Yes, if we wanted this to handle cases like "div, p" right, you can't  
just do a simple prepend of ":scope", you have to treat it as ":scope  
div, :scope p". Such an API would make clear that we were introducing  
a new notion of "scoped selector" which differs from selectors in the  
CSS sense. Also, this could be specified in Selectors API without  
waiting for :scope to make it into a spec, by saying the selector acts  
as if some simple selector that uniquely matches the scope node had  
been prepended to each selector in the group.

> The only real downside with that proposal is that the passed in  
> selector is not a valid selector. And it doesn't work really well  
> for selector groups such as "div, span", where what you'd really  
> want is for ":scope" to be prepended to each group, which makes  
> parsing a lot of fun...

Yes, unfortunately I think significant parsing hackery would be  
required to handle this. Either a second Selector parser, or a special  
pre-parser that could inject ":scope" or nonstandard equivalent in the  
right places. Or we could just say that a "scoped selector" can only  
be a selector, not a group of selectors, so commas are a syntax error.

Regards,
Maciej
Received on Saturday, 3 May 2008 01:44:57 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 3 May 2008 01:44:58 GMT