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

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

From: Doug Schepers <schepers@w3.org>
Date: Tue, 01 Apr 2008 13:13:13 -0400
Message-ID: <47F26D29.6090008@w3.org>
To: "Web APIs WG (public)" <public-webapi@w3.org>

Hi, Henri-

Henri Sivonen wrote (on 4/1/08 10:36 AM):
> 
> 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?

Again, childElementCount is not intended for index access.  It's 
intended as a preprocessing convenience for script authors.  This saves 
the costly DOM operation of having to process the loop twice in script, 
once to count the elements, and another to set values based on the total 
number of elements.

As an SVG author, this is something I've needed many times.

Regards-
-Doug Schepers
W3C Team Contact, SVG, CDF, and WebAPI
Received on Tuesday, 1 April 2008 17:13:45 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 1 April 2008 17:13:45 GMT