Re: Some way to change an element's name would be useful

On Aug 29, 2011, at 20:57 , Aryeh Gregor wrote:
> We can't actually change the tag name of the node in place, because
> then it will have to implement a different interface in general.  But
> we could have a setTagName() method that creates a new Element with
> the given tag name, moves the children, copies the attributes, puts it
> in the right place, fixes up the Ranges, then returns the
> newly-created Element.  Does this seem reasonable to anyone, or is it
> too confusing that the object will be different?

I've often had a need for this, and I agree that it would be useful. It certainly is confusing that it returns a different object but maybe we can alleviate that problem somewhat with a different method? Not to bikeshed, but setTagName() sounds like you're setting a property of a given object, which makes the object change confusing. Perhaps something like renameElement() would be clearer? Or getRenamedElement()?

For completeness, I'm guessing that namespaces would be supported as well?

Element renameElement(DOMString newName);
Element renameElement(DOMString newNS, DOMString newName);

-- 
Robin Berjon - http://berjon.com/ - @robinberjon

Received on Monday, 29 August 2011 19:34:32 UTC