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

19.01.2012, 05:17, "Alex Russell" <slightlyoff@google.com>:
> On Tue, Jan 10, 2012 at 11:02 AM, Marat Tanalin | tanalin.com
> <mtanalin@yandex.ru> wrote:
>
>> š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;
>
> Without doing the contextual prepending with ":scope", this is
> nonsensical for qSA, AFAICT.

Why should be it nonsensical for qSA while being OK for findAll?

>> š2. use ':scope' with find(All) same way and with the same result as with qS(A).
>
> That will be allowed by the current draft.

So 'will' (some future draft) or 'current' (draft available right now)?

Received on Thursday, 19 January 2012 15:06:18 UTC