W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: QSA, the problem with ":scope", and naming

From: Sean Hogan <shogun70@westnet.com.au>
Date: Wed, 19 Oct 2011 22:58:34 +1100
Message-ID: <4E9EBB6A.8060607@westnet.com.au>
To: Ojan Vafai <ojan@chromium.org>
CC: Boris Zbarsky <bzbarsky@mit.edu>, public-webapps@w3.org
On 19/10/11 2:39 PM, Ojan Vafai wrote:
> Overall, I wholeheartedly support the proposal.
> I don't really see the benefit of allowing starting with a combinator. 
> I think it's a rare case that you actually care about the scope 
> element and in those cases, using :scope is fine. Instead of 
> element.findAll("> div > .thinger"), you use element.findAll(":scope > 
> div > .thinger"). That said, I don't object to considering the :scope 
> implied if the selector starts with a combinator.

I can think of two reasons one might ponder allowing :scope to be explicit.

1. so that the selector string can be a valid CSS selector string. 
(":scope>div>.thinger" instead of ">div>.thinger"). But if this is 
important then :scope should always be explicit, in which case we can 
just use querySelectorAll().

2. to allow break-out behavior. e.g.

div.findAll("body div span"); // finds nothing
div.findAll("body div:scope span"); // finds span's that are descendants 
of div

In this scenario, the :scope pseudo allows ancestors of div to be 
matched against. (No-one would use body in this context, but it is easy 
to imagine them using a .class selector which matches an ancestor of div.)

But if you want break-out behavior you might not know which part of the 
selector to put the :scope pseudo on. Could it be:
     body div:scope span
     body *:scope div span
     body div *:scope span

So for break-out behavior just use querySelectorAll().

I'm pretty sure previous discussions (before this thread) have covered 
this more thoroughly, and shown that it has to be all or nothing with 
the :scope pseudo-attribute. That is, either
a) :scope MUST be explicit, in which case just use querySelectorAll()
b) :scope MUST be implied at the start of every selector chain.

Received on Wednesday, 19 October 2011 11:59:09 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:36 UTC