how to display a javascript var in html body

Try This…

<html>

<head>
  <script>
    function myFunction() {
      var number = "123";
      document.getElementById("myText").innerHTML = number;
    }
  </script>
</head>

<body onload="myFunction()">

  <h1>"The value for number is: " <span id="myText"></span></h1>

</body>

</html>

Leave a Comment