Remove child element but keep its content - Javascript DOM

Javascript examples for DOM:Element innerHTML

Description

Remove child element but keep its content

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.  java2 s .c o m
var x = document.getElementById("test");
var y = document.getElementById("testChild").innerHTML;
x.addEventListener('click', function () {
    this.innerHTML = y;
})
    }

      </script> 
   </head> 
   <body> 
      <span id="test">
         <strong id="testChild">Test without styles</strong>
      </span>  
   </body>
</html>

Related Tutorials