Change tag using javascript

html, javascript

Solution

You can't change the type of an element like that, instead you have to create a new element and move the contents into it. Example:

var e = document.getElementsByTagName('span')[0];

var d = document.createElement('div');
d.innerHTML = e.innerHTML;

e.parentNode.replaceChild(d, e);

Demo: http://jsfiddle.net/Guffa/bhnWR/

Problem

I want to know how can I change a tag with pure javascript like that ``` <span>some text</span> ``` I want to change it to that ``` <div>some text</div> ``` I have no idea how to do it.

Original source

Related problems