How to insert HTML into a div with JavaScript?

Sometimes, we want to insert HTML into a div with JavaScript.

In this article, we’ll look at how to insert HTML into a div with JavaScript.

How to insert HTML into a div with JavaScript?

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.

Conclusion

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