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

Re: modifying the DOM WAS: Node append

From: Sean Hogan <shogun70@westnet.com.au>
Date: Thu, 06 Oct 2011 22:40:50 +1100
Message-ID: <4E8D93C2.8090806@westnet.com.au>
To: Ojan Vafai <ojan@chromium.org>
CC: Anne van Kesteren <annevk@opera.com>, Aryeh Gregor <ayg@aryeh.name>, Erik Arvidsson <arv@chromium.org>, Olli@pettay.fi, Boris Zbarsky <bzbarsky@mit.edu>, Robin Berjon <robin@berjon.com>, www-dom@w3.org, Alex Russell <slightlyoff@chromium.org>
On 4/10/11 8:30 AM, Ojan Vafai wrote:
> Upon more thought, I've come to believe that we should add new methods 
> that just do what we want instead of trying to retrofit the old ones. 
> The old methods can continue to function on just nodes, avoiding any 
> concerns of killing the performance of existing sites and providing an 
> opportunity for performance optimizations for sites that really need it.

Another reason new methods would be appropriate is that currently 
appendChild(), insertBefore()
return the node that was inserted. If inserting a DocumentFragment node 
this leaves you with an empty floating fragment, which probably isn't 
what you wanted. I would suggest that returning the node on which the 
method is invoked is more useful.

> Specifically, lets add the following methods to Node:
> prepend(nodeish) - Adds to the start of the node.
> append(nodeish) - Adds to the end of the node.
> before(nodeish) - Adds before the node.
> after(nodeish) - Adds after the node.
> replace(nodeish) - Replaces the node.
> remove() - Removes the node.

One of the potential benefits of these proposed methods (when called 
with an array-ish of nodes) is improved performance as several DOM calls 
are replaced with one. For the same reason I think consideration should 
be given to setting multiple attributes with one DOM call.

Received on Thursday, 6 October 2011 11:41:16 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:36:59 UTC