Using AppendChild on body element with text content - Javascript DOM

Javascript examples for DOM:Element appendChild

Description

Using AppendChild on body element with text content

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 . ja v  a  2s.com
var infoDiv = document.createElement("div");
infoDiv.setAttribute("class", "text-block");
var bio = document.createElement("strong");
bio.textContent = "Bio";
infoDiv.appendChild(bio);
infoDiv.innerHTML += "Full";
document.getElementsByTagName("body")[0].appendChild(infoDiv)
    }

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

Related Tutorials