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

Ok, guys, let's see it that way : we have one given element and we
want to find its 3rd element child. Very simple and common query,
right ?

1. using my proposal :

    myFooElement.childElements.item(3);

2. using Selectors API :

    myFooElement.querySelector("*:nth-child(3)") does NOT work since
    there can be another 3rd child in traversal order before the
    3rd child of myFooElement. I have no way of querying the 3rd child
    of myFooElement alone if myFooElement has no ID, no class, nothing
    since the :root pseudo-class does NOT apply to myFooElement in such
    a query but still represents the root of the document.
    Querying  :first-child+*+*  does not work either for the same reason,
    there can be a 3rd child deep in the subtree being before the 3rd
    child of myFooElement in traversal order of the document...

    This is a limitation of the Selectors API I detected long ago.
    Mentioned it a few times, too.

3. using XPath :

    document.evaluate('*[3]', myFooElement, null,
                      XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                      null).snapshotItem(3);

How much do you bet that if you show this to web designers, they'll
find solution (1) usable and will probably SCREAM LOUDLY at
(2) and (3) ?

</Daniel>

Received on Friday, 28 March 2008 16:56:23 UTC