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:

HTML file: Displayed by browser:
<!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>

My First Web Page

My First Paragraph

To "display data" in HTML, (in most cases) you will set the value of an innerHTML property.

BackTable of ContentsNext