change HTML tag name using Pure JS
问题 <div id="demo"></div> document.getElementsById("demo").onclick = function() { this.tagName = "p"; }; // and then the output should be: <p id="demo"></p> I want to use pure javascript to change the tag name, could anyone help please? 回答1: With some snazzy dom Manipulation you can do this easely. You simply need to make a new element, move over all the elements so you keep onclick handlers and such, and then replace the original thing. function addClickEventToSpan() { document.getElementById(