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

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

From: Marat Tanalin | tanalin.com <mtanalin@yandex.ru>
Date: Tue, 10 Jan 2012 23:02:42 +0400
To: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Cc: Tab Atkins Jr. <jackalmage@gmail.com>,public-script-coord@w3.org
Message-Id: <76621326222162@web84.yandex.ru>
10.01.2012, 17:53, "Lachlan Hunt" <lachlan.hunt@lachy.id.au>:
> 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/

OK, thank you for your attention.

Then I would propose to make querySelector(All)/find(All) at least as consistent with each other as possible.

In other words, the only difference between them should be the thing that was the reason to invent new find(All) methods themselves -- default selector-matching scope (document root-element in qS(A) and reference element in find(All)).

So we should, for example (but not limited to), be able to:

1. start selector from combinator ('>' in particular) in _both_ find(All) and qS(A), and with the same result;
2. use ':scope' with find(All) same way and with the same result as with qS(A).

Received on Tuesday, 10 January 2012 19:05:58 UTC

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