HS Banner
Back
JavaScript Output

Author: b.henry 03/18/2021
Language: JavaScript
Views: 276
Tags: javascript


Description:

Here's an example of javascript using innerHTML

Article:

JavaScript Display Possibilities

JavaScript can "display" data in different ways:

  • Writing into an HTML element, using innerHTML.
  • Writing into the HTML output using document.write().
  • Writing into an alert box, using window.alert().
  • Writing into the browser console, using console.log().

Using innerHTML

To access an HTML element, JavaScript can use the document.getElementById(id) method.

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>

JavaScript Output (w3schools.com)

Full Source Code:
<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My First Paragraph</p>

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

<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>

</body>
</html>


Back
Comments
Add Comment
There are no comments yet.