Add elements to the DOM with plain text HTML using JavaScript - Javascript DOM

Javascript examples for DOM:Document createElement

Description

Add elements to the DOM with plain text HTML 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  ww  w  .j  av a 2 s.co m*/
var el =  document.createElement("h1")
el.id="title";
el.innerHTML = "Some title";
document.body.appendChild(el);
var el2 =  document.createElement("span")
el2.style.display="block";
el2.style.width="100%";
el2.innerHTML = "Some arb text";
document.body.appendChild(el2);
    });

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

Related Tutorials