Re: Improving the DOM

On Wed, 09 Nov 2011 02:19:00 +0100, Jonas Sicking <jonas@sicking.cc> wrote:

> I think .before, .after and .remove should be available on all nodes
> which can appear in the normal document tree, including PIs and

PI is CharacterData in DOM4.

> DocTypes. There's no reason to be inconsistent here and it'll just
> make it annoying for people that are iterating over the tree and
> perform operations on it. I agree that DocTypes/PIs aren't commonly
> used, but they do appear in the DOM now and then and it makes it even
> worse for authors if they have to explicitly handle those types of
> nodes different.
>
> As for .append and .prepend, I think we should make those exist on all
> nodes which can have children, including Documents. This for the same
> reason, it makes things more consistent for authors.
>
> I don't think it's our job to pass judgement on what nodes people
> should or should not be modifying or having in their DOM.
>
> / Jonas

I agree.

One use case could be to replace everything in a document with new nodes:

while (document.hasChildNodes())
   document.firstChild.remove();
document.append(newroot);

-- 
Simon Pieters
Opera Software

Received on Wednesday, 9 November 2011 07:41:21 UTC