W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: querySelectorAll() -- selecting _immediate_ children of element

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Tue, 10 Jan 2012 14:53:37 +0100
Message-ID: <4F0C42E1.50301@lachy.id.au>
To: "Marat Tanalin | tanalin.com" <mtanalin@yandex.ru>
CC: "Tab Atkins Jr." <jackalmage@gmail.com>, public-script-coord@w3.org
On 2012-01-09 18:22, Marat Tanalin | tanalin.com wrote:
> However there is no need for new findAll() method. We can do the
> same  with existing qS/qSA.
>
> Nor we need second parameter in querySelectorAll. This addition
> looks  like something purely theoretical (by the way, I've not found it in the
> draft you've linked to). We need just subject element (which's qS/qSA
> method is called) to be expressable inside selector.

It's not theoretical.  It closely resembles the feature in JQuery, which 
supports $(selector, context), where context may be or or more elements 
in a collection or JQuery object.

> Even if second parameter for qS/qSA will be in the spec, it should
> be  equal to subject element by default so that we couldn't be forced to
> explicitly pass subject element every time:

Yes, that's what the spec says.

>      // Absurd non-DRY way: refElement is passed as argument to method of itself.
>      refElement.querySelectorAll(':scope>  div', refElement);

Although support for the second parameter has since been removed from 
querySelector() and querySelectorAll(), it never required you to pass 
refElement as the second parameter if it was the same as the context 
object.  The algorithm to determine contextual reference nodes in the 
spec handles this by defaulting to the context element if no other 
elements were provided.

Now, however, the refNodes parameter is only supported for find() and 
findAll() on Document and DocumentFragment objects.  It is no longer 
supported on elements in favour of :scope always matching the context 
object.

>      // Correct way: ':scope' is refElement by default.
>      refElement.querySelectorAll(':scope>  div');

That is exactly how it was, before refElement/refNodes were removed from 
qSA, and it is how it works with find()/findAll().

   refElement.findAll(":scope>div")

But that case is also equivalent to:

   refElement.findAll(">div");

> Furthermore, ':scope' looks like inoptimal name for pseudoclass since
> it may lead to confusion/conflicts between HTML5 scopes defined with
> 'scope' attribute and scopes inside qS/qSA.

That particular pseudo-class was named and defined with both <style 
scoped> and qSA in mind. It matches entirely based on the context in 
which it is used.  Various other names have been tried in the past, 
including :context, :ref, :this, etc. but none were found to be as 
accepted as :scope was.

-- 
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/
Received on Tuesday, 10 January 2012 13:54:42 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:05 UTC