W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2003

Re: node.insertBefore( child )

From: Luca Padovani <lpadovan@cs.unibo.it>
Date: Wed, 03 Dec 2003 20:24:32 +0100
To: Chris Moschini <cmoschini@myrealbox.com>
Cc: www-dom@w3.org
Message-Id: <1070479472.30798.5.camel@giraffe>

Hi,

On Wed, 2003-12-03 at 19:34, Chris Moschini wrote:
> for( i = 0; i < len; i++ ) {
>   if( node.childNodes.length == 0 )
>     last = node.appendChild( list[ i ] );
>   else
>     node.insertBefore( list[ i ], last );
> }

what about

for( i = 0; i < len; i++ )
  node.insertBefore(list[i], node.firstChild());

?
ok there are two method calls instead of only one but I think this is
acceptable (and inserting at the beginning of the list is IMHO less
common than appending)

-- luca
Received on Wednesday, 3 December 2003 14:29:21 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:57 GMT