Create text node with createTextNode() and set it to span - Javascript DOM

Javascript examples for DOM:Document createTextNode

Description

Create text node with createTextNode() and set it to span

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(){/*from   w w  w.j  a  v a 2 s  .co  m*/
var td1 = document.getElementById('Fruit'),
    text = document.createTextNode("Apple");
td1.replaceChild(text,td1.firstChild);

    }

      </script> 
   </head> 
   <body> 
      <span id="Fruit">Banana</span>  
   </body>
</html>

Related Tutorials