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

Re: [SelectorsAPI] Thoughts on querySelectorAll

From: Jonas Sicking <jonas@sicking.cc>
Date: Fri, 02 May 2008 17:35:38 -0700
Message-ID: <481BB35A.8050100@sicking.cc>
To: John Resig <jresig@mozilla.com>
CC: Lachlan Hunt <lachlan.hunt@lachy.id.au>, public-webapi@w3.org

>> 3. Introducing a :scope selector (or equivalent) solves all the issues
>> you have raised, without sacrificing potentially useful functionality.
>> :scope would also be useful in contexts outside of Selectors API, such
>> as within HTML5's scoped stylesheets and possibly XBL.
> 
> Sure, it solves the technical problem but it doesn't solve the actual problem: The API is broken in its current state.

I'm having a hard time understanding your definition of "broken". It 
just doesn't work the way you expect it to, which is IMHO something 
different.

However, I do see your point in that the behavior can be unexpected, 
especially given how many people are currently used to the way many 
toolkits work today.

But we still need an alternative proposal, which so far no-one has proposed.

You suggested that "div span" should only select nodes where both simple 
selectors are tested against descendants of the context node. But then 
you said that in ":scope span" the first selector should be tested 
against (and obviously should match) the context node itself.

So should there be an exception to the "test only against descendants" 
rule if a selector contains a ":scope" pseudo class? Or only if a 
selector is exactly the ":scope" selector? I.e. what should "div:scope 
span" match? Can the "div" part there match the context node, or will 
such a selector never match anything? I know some of this is more or 
less useless, but my question is how you suggest that this actually 
should work.

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.

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...

/ Jonas
Received on Saturday, 3 May 2008 00:37:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 3 May 2008 00:37:11 GMT