How to load an HTML page in a div using JavaScript?

Spread the love

Sometimes, we want to load an HTML page in a div using JavaScript.

In this article, we’ll look at how to load an HTML page in a div using JavaScript.

How to load an HTML page in a div using JavaScript?

To load an HTML page in a div using JavaScript, we set the innerHTML property of the element.

For instance, we write

document.getElementById("content").innerHTML =
  '<object type="text/html" data="home.html" ></object>';

to select the element with getElementById.

Then we set its innerHTML property to the string with the HTML we want to render.

Conclusion

To load an HTML page in a div using JavaScript, we set the innerHTML property of the element.

Leave a Reply

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