Set value to an element returned from document.getElementById(...) - Javascript DOM

Javascript examples for DOM:Document getElementById

Description

Set value to an element returned from document.getElementById(...)

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script>
  window.onload = function () {//  w  w w.j  ava  2s  .com
    var x = 5;
    var y = 6;
    var z = x + y;
    document.getElementById("add").innerHTML = z;
  };

      </script> 
   </head> 
   <body> 
      <h1>Demo</h1> 
      <div id="demo">
         Addition of 5 and 6 is 
         <span id="add"></span> 
      </div>  
   </body>
</html>

Related Tutorials