Skip to content

innerHTML JavaScript | DOM Property

  • by

The innerHTML property is used in JavaScript sets or returns the HTML content (inner HTML) of an element. It can be used to write the dynamic HTML on the html document.

Return the innerHTML property:


Set the innerHTML property:

 HTMLElementObject.innerHTML = value

To insert the HTML into the document rather than replace the contents of an element, use the method insertAdjacentHTML().

Example innerHTML JavaScript

Simple example code Get the HTML content of a <p> element with id=”myName”:

<!DOCTYPE html>

  <p id="myName">EyeHunts Tutorial</p>
  <button onclick="myFunction()">Get MSG</button>

    function myFunction() {
      var x = document.getElementById("myName").innerHTML;



innerHTML JavaScript

Set the HTML content of a <p> element with id=”demo”:


  <p id="demo">EyeHunts Tutorial</p>
  <button onclick="myFunction()">Change</button>

    function myFunction() {
     document.getElementById("demo").innerHTML = "Hello";


Do comment if you have any doubts or suggestions on this JS HTML topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *