var el = document.getElementById(id); var new = document.createElement("span"); new.id = el.id; [].forEach.call(el.childNodes, function (node) { new.appendChild(node); }); el.parentNode.replaceChild(new, el);
Now, the good question is why. Why do you want to change the html element?
Of course, you choose the most semantic element for this piece of data, why should another element be a better choice?
source share