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

On Apr 1, 2008, at 17:36, Henri Sivonen wrote:
> 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.


Even cleaner if written as a for loop:
for (var e = p.firstElementChild; e != null; e = e.nextElementChild) {
   ...
}

-- 
Henri Sivonen
hsivonen@iki.fi
http://hsivonen.iki.fi/

Received on Tuesday, 1 April 2008 14:55:42 UTC