Re: modifying the DOM WAS: Node append

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.

Sean

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