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

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

From: Henri Sivonen <hsivonen@iki.fi>
Date: Tue, 1 Apr 2008 17:36:46 +0300
Cc: "Web APIs WG (public)" <public-webapi@w3.org>
Message-Id: <7E00024C-3BB2-40CC-B7F6-718C69DF9AE3@iki.fi>
To: Daniel Glazman <daniel.glazman@disruptive-innovations.com>

On Mar 28, 2008, at 16:42, Daniel Glazman wrote:
> 2. the ElementTraversal interface has a |childElementCount| attribute
>   but misses access to an individual childElement based on its index.
>   That would be really useful. Two solutions here :
>   a. you remove the childElementCount attribute in favor of a
>        readonly attribute NodeList    childElements;
>      and that NodeList has all we need
>   b. you add
>        Node    item(in unsigned long index);
>      but that is not really consistent with the existing way of
>      querying list of nodes.
>   My very strong preference goes to solution a.

c. just remove the childElementCount attribute

It seems to me that checking if an element has *any* element children  
is going to be the most common use case for childElementCount and that  
can be checked by checking if firstElementChild is null.

I very much like the idea having firstElementChild, lastElementChild,  
previousElementSibling, nextElementSibling. In particular, I think using
var e = p.firstElementChild;
while (e != null) {
   e = e.nextElementChild
to iterate over child elements is a cleaner idiom than introducing an  
index that isn't used for random access but only for forward iteration.

How often do people pick a single child by index (with a number know a  
priori) instead of iterating over children and testing each one for an  
interesting trait?

Henri Sivonen
Received on Tuesday, 1 April 2008 14:37:30 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:10:00 UTC