Add text to a tag using innertext and add to an id of a div - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Add text to a tag using innertext and add to an id of a div

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 .  jav  a  2s. c  om
var example = document.getElementById('divone');
var h1 = document.createElement('h1');
h1.innerText = "hi";
example.appendChild(h1);
    }

      </script> 
   </head> 
   <body> 
      <div id="divone"> 
      </div>  
   </body>
</html>

Related Tutorials