Javascript Home

Output

Using innerHTML

The id attribute defines the HTML element. The innerHTML property defines the HTML content.


  <p id="demo"></p>

  <script>

    document.getElementById("demo").innerHTML = 5 + 6;

  </script>

Using document.write()

For testing purposes, it is convenient to use document.write().



  <script>

    document.write(5 + 6);

  </script>


Never call document.write after the document has finished loading. It will overwrite the whole document.


  <button type="button" class="btn btn-primary mb-5" onclick="document.write(5 + 6)">Try it</button>


Using window.alert()

You can use an alert box to display data.


  <button type="button" class="btn btn-primary mb-5" onclick="myFunction()">Click me</button>

  <script>

    function myFunction() {

      window.alert(5 + 6);

    }

  </script>