Change element from <span> to <h1> by creating a new element and swap - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Span

Description

Change element from <span> to <h1> by creating a new element and swap

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  w  w w . j  a  v a2 s .  c om
var mySpan = document.getElementById("myId");
var myH1 = document.createElement("h1");
myH1.innerHTML = mySpan.innerHTML;
mySpan.parentNode.replaceChild(myH1, mySpan);
    }

      </script> 
   </head> 
   <body> 
      <span id="myId">Hello</span>  
   </body>
</html>

Related Tutorials