Re: [selectors-api] comments on Selectors API Level 2

On Thu, Jan 21, 2010 at 10:11 AM, Bert Bos <bert@w3.org> wrote:
> 2) Drop queryScopedSelector() and queryScopedSelectorAll(). It is
> trivially easy to replace a call to queryScopedSelector() by a call to
> querySelector(). All you have to do is replace
>
>    e.queryScopedSelector(x)
> by
>    e.ownerDocument.querySelector(x)

That's completely incorrect.  A querySelector call on the document
will return all elements that match the selector.  A
queryScopedSelector call on an element will only return elements that
match the selector in the target element's subtree.

> where e is an Element. And for documents d the functions are even
> exactly the same: d.queryScopedSelector(x) == d.querySelector(x) for
> all documents d and selectors x.

That doesn't solve the problem, it just says "We don't need to solve
this problem.".  A scoped call on the document root is indeed the same
as a non-scoped selector, but that doesn't tell us anything about the
actual scoped behavior.  It's a degenerate case.

> Somebody somewhere else was wondering about the selector ':root + *'. I
> would say it's a valid selector that just happens to never match
> anything, because a tree by definition has only one root. The same
> holds for selectors like '#foo #foo' (valid, but guaranteed to return
> nothing, because IDs are by definition unique), '*:first-child:even'
> (the first child is obviously odd, not even), and ':root:first-child'
> (the root is not a child of anything).

In a scoped selector, ":scope + *" *should* return something, if the
scoping element has a sibling.  It's the behavior of jQuery's find()
method (try elem.find("+ *")), and it's what authors are used to.  The
entire *point* of scoped selectors was to fix the disconnect between
querySelector and jQuery, basically.  Adding yet another selector
function that doesn't act like what current widely-adopted libraries
need or what authors expect doesn't help anyone.

I don't like the requirement of :scope either, but Lachy took Anne's
dislike of starting the string with a bare combinator to be the WG's
position as a whole.  I think matching jQuery here is *very* important
both for author expectations and for practical benefit, and so having
e.queryScopedSelectorAll("+ *") do the exact same thing as
$(e).find("+ *") is essential.

~TJ

Received on Thursday, 21 January 2010 16:34:19 UTC