Re: QSA, the problem with ":scope", and naming

On Fri, Oct 21, 2011 at 12:41 AM, Jonas Sicking <jonas@sicking.cc> wrote:
> On Thu, Oct 20, 2011 at 2:33 PM, Lachlan Hunt <lachlan.hunt@lachy.id.au>
> wrote:
>> Not necessarily.  It depends what exactly it means for a selector to
>> contain
>> :scope for determining whether or not to enable the implied :scope
>> behaviour.  Consider:
>>
>>  foo.find(":not(:scope)");
>
> Ooh, this is an interesting case too. So here's the full list of cases which
> we need defined behavior for (again looking at Alex and Yehuda here).
>
> In the following DOM
>
> <body id="3">
>  <div id=0></div>
>  <div id="context" foo=bar>
>   <div id=1></div>
>   <div class="class" id=2></div>
>   <div class="withChildren" id=3><div class=child id=4></div></div>
>  </div>
>  <div id=5></div>
>  <div id=6></div>
> </body>
>
> What would each of the following .findAll calls return. I've included my
> guessed based on the discussions so far:
>
> var e = document.getElementById('context');
>
> e.findAll("div")  // returns ids 1,2,3,4
> e.findAll("")      // returns an empty list
> e.findAll("#3")  // returns id 3, but not the body node
> e.findAll("> div") // returns ids 1,2,3
> e.findAll("[foo=bar]") // returns nothing
> e.findAll("[id=1]") // returns id 1
> e.findAll(":first-child") // returns id 1
> e.findAll("+ div") // returns id 5
> e.findAll("~ div") // returns id 5, 6
> e.findAll(":scope")

Returns the context.

> e.findAll("div:scope")

Returns the context.

> e.findAll("[foo=bar]:scope")

Returns the context.

> e.findAll(":scope div")

1, 2, 3, 4

> e.findAll("div:scope div")

1, 2, 3, 4

> e.findAll("div:scope #3")

3

> e.findAll("body > :scope > div")

1, 2, 3, 4

> e.findAll("div, :scope")

context, 1, 2, 3, 4

> e.findAll("body > :scope > div, :scope")

context, 1, 2, 3, 4

> e.findAll(":not(:scope)")

empty set

Received on Monday, 31 October 2011 20:56:28 UTC