I need to convert a DOM element to a different type (as in HTML tag name, a
to p
in this case), but still retain all the original elements attributes. Whether they are valid for the new type or not doesn't matter in this case.
Any suggestions on how to do this?
I've looked at just creating a new element and copying the attributes across, but this isn't without it's own complications. In Firefox, DOMElement.attributes
helpfully only includes attributes with a value, but in IE it reports all possible attributes for that element. The attributes
property itself is read-only, so no way to copy that.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…