Create <h1> element and assign its text - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Heading

Description

Create <h1> element and assign its text

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  ww w  . j a  va 2s. co m
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