Create <div> element and set its content, then add to body - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Create <div> element and set its content, then add to body

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() {/* w w w  . j ava2s .  com*/
var response = {results: 123, id: 456};
var div = document.createElement("div");
div.innerHTML = "id: " + response.id + " results: " + response.results;
document.getElementsByTagName("body")[0].appendChild(div);
    });

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

Related Tutorials