JavaScript innerHTML JAVASCRIPT

JavaScript innerHTML  

JavaScript innerHTML

JavaScript innerHTML

Changing the innerHTML property of an HTML element is a common way to display data in HTML.

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:

Example

<!DOCTYPE html>
<html>
<body>

<h2>My First Web Page</h2>
<p>My First Paragraph.</p>

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

<p id="demo2"></p>

<script>
document.getElementById("demo").innerHTML = 15 + 16;

document.getElementById("demo2").innerHTML = 'innerHTML example ';
</script>

</body>
</html>

Download free E-book of JAVASCRIPT


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries