Insert HTML element to body two times using JavaScript - Javascript DOM

Javascript examples for DOM:Element appendChild

Description

Insert HTML element to body two times using JavaScript

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  av a 2s .c o  m*/
    var div = document.createElement('div');
    div.innerText = 'Hello!';
    var div2 = document.createElement('div2');
    div2.innerText = 'Hello2!';
    document.body.appendChild(div);
    document.body.appendChild(div2);
    document.body.appendChild(div);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials