Use div to show function result - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Use div to show function result

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div id="resultsDiv"> 
         <h3>Results Here:</h3> 
      </div> 
      <script type="text/javascript">
    var sum = 0;//from w  ww  .  j  a v  a  2  s. c om
    var resultsDiv = document.getElementById('resultsDiv');
    for (var i = 0; i < 1000; i++) {
      if (i % 3 === 0 || i % 5 === 0 || i % 7 === 0) {
        sum += i;
      }
      resultsDiv.innerHTML += 'The sum is' + " " + sum + "<br />";
    }
  
      </script>  
   </body>
</html>

Related Tutorials