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:


<!DOCTYPE html>

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

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

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

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

document.getElementById("demo2").innerHTML = 'innerHTML example ';


Download free E-book of JAVASCRIPT

Learn Programming for Free

Join Programmers Community on Telegram

Talk with Experienced Programmers

Just drop a message, we will solve your queries