Categories
JavaScript Answers

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

Spread the love

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

For instance, we write

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

to select the wrapper element with getElementById.

And then we set its innerHTML property to a string with an object element that loads the home.html page.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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