Javascript examples for DOM:Element innerHTML
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 |
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":
<!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>