HTML | DOM innerHTML Property
The DOM innerHTML property is used to set or return the HTML content of an element.
Syntax:
- It returns the innerHTML Property.
Object.innerHTML
- It is used to set the innerHTML property.
Object.innerHTML = value
Where value represents the text content of HTML element.
Return Value: This property returns a string which represents the HTML content of an element.
Example-1: This example shows how to change the content of the paragraph tag using innerHTML property.
<!DOCTYPE html> <html> <head> <title>DOM innerHTML Property</title> </head> <body style="text-align: center"> <h1 style="color:green"> GeeksforGeeks </h1> <h2> DOM innerHTML Property </h2> <p id="p">GeeksforGeeks</p> <button onclick="geek()">Click me!</button> <script> function geek() { document.getElementById("p").innerHTML = "A computer science portal for geeks."; } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Example-2: This example shows how to get the value of paragraph tag using innerHTML property.
<!DOCTYPE html> <html> <head> <title>DOM nextSibling Property</title> </head> <body style="text-align: center"> <h1 style="color:green"> GeeksforGeeks </h1> <h2> DOM innerHTML Property </h2> <p id="P">A computer science portal for geeks.</p> <button onclick="geek()">Try it</button> <p id="p"></p> <script> function geek() { var x = document.getElementById("P").innerHTML; document.getElementById("p").innerHTML = x; document.getElementById("p").style.color = "green"; } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Supported Browsers: The browser supported by innerHTML property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to replace innerHTML of a div using jQuery?
- Difference between innerText and innerHTML
- How to add innerHTML to print page?
- HTML | DOM id Property
- HTML | DOM Bdo dir Property
- HTML | DOM li value Property
- HTML | DOM value Property
- HTML | DOM specified Property
- HTML | DOM URL Property
- HTML | DOM dir Property
- HTML | DOM name Property
- HTML | DOM IFrame src Property
- HTML | Window top( ) Property
- HTML | Window self( ) Property
- HTML | DOM Image name Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



