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

On Tue, Jan 10, 2012 at 11:02 AM, Marat Tanalin |
<> wrote:
> 10.01.2012, 17:53, "Lachlan Hunt" <>:
>> On 2012-01-09 18:22, Marat Tanalin | 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
> 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.

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

Received on Thursday, 19 January 2012 01:18:30 UTC