Javascript - Change html tag type

后端 未结 8 1139
说谎
说谎 2020-11-30 14:03

i have a question, can i replace html tag to another ?

But i don\'t want to make the content blank. like this:

content<         


        
8条回答
  •  执笔经年
    2020-11-30 14:48

    No. You cannot change the tagName (nodeName) of a DOM node.

    You only could create a new node of the wanted type, copy all attributes (and maybe properties) and move the child nodes. Yet you would loose inaccessible things like attached event listeners. This technique is for example used when you want to change the type of an input in IE.

    However, there is absolutely no reason to change an a into a div, they have completely different semantics (also behaviour and layout).

提交回复
热议问题