JavaScript Answers

How to insert HTML into a div with JavaScript?

Spread the love

To insert HTML into a div with JavaScript, we can set the innerHTML property.

For instance, we write

document.getElementById("tag-id").innerHTML = "<ol><li>html data</li></ol>";

to select the div with getElementById.

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

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.