Element innerHTML Property - Javascript DOM

Javascript examples for DOM:Element innerHTML

Description

The innerHTML property sets or gets the HTML content of an element.

Set the innerHTML property with the following Values

Value Description
text Sets the HTML content of an element

Return Value

A String, representing the HTML content of an element

The following code shows how to change the HTML content of a <p> element with id="demo":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<h1>My Web Page</h1>

<p id="myP">This is a p element.</p>

<div id="myDIV">This is a div element.</div>

<script>
document.getElementById("myP").innerHTML = "Hello Dolly.";
document.getElementById("myDIV").innerHTML = "How are you?";
</script>/*  w  w w. j  a v  a2 s  . c o m*/

</body>
</html>

Related Tutorials