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:54:58 +0300
Message-Id: <84ECE049-18B8-44ED-893B-05B4A5066AFC@iki.fi>
To: "Web APIs WG (public)" <public-webapi@w3.org>

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 1 April 2008 14:55:43 GMT