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

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

Thanks.

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