W3C home > Mailing lists > Public > public-webapi@w3.org > March 2008

Re: [Element Traversal LC] access to element by index

From: Bjoern Hoehrmann <derhoermi@gmx.net>
Date: Sat, 29 Mar 2008 18:27:37 +0100
To: Daniel Glazman <daniel.glazman@disruptive-innovations.com>
Cc: Boris Zbarsky <bzbarsky@MIT.EDU>, "Web APIs WG (public)" <public-webapi@w3.org>
Message-ID: <hkusu3had1j028ue67mlq61rpqa8hi93ho@hive.bjoern.hoehrmann.de>

* Daniel Glazman wrote:
>> Being devil's advocate for a sec, having a :scope pseudo-class or some 
>> such would help here, right?
>> 
>>   myFooElement.querySelector(":scope > :nth-child(3)")
>
>That would require an addition to the Selectors spec and that comes
>too late in the process of that spec. I would recommend changing
>the Selectors API on document.querySelector and
>document.querySelectorAll to allow a second argument being a node or
>null. If it's a node, then the results simulate your :scope > SELEC
>above, the scope being that node and SEL being the selector passed as
>the 1st argument. If it's null, well, it does what it does today.

It would be easier to define that, if the argument starts with a non-
white space combinator, it is prefixed with a selector that selects the
element node it is called on and only that node. That would give you

  myFooElement.querySelectorAll(">*")[3]

We could also standardize the popular .getChildrenByTagName() method,
that would give the similar

  myFooElement.getChildrenByTagName("*")[3]

Either would be preferable over

  myFooElement.querySelector(":nth-child(3)", null, myFooElement)

As your proposal would have it.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 
Received on Saturday, 29 March 2008 17:28:21 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 29 March 2008 17:28:23 GMT