How to add elements to the DOM given plain text HTML using only pure JavaScript?

Sometimes, we want to add elements to the DOM given plain text HTML using only pure JavaScript.

In this article, we’ll look at how to add elements to the DOM given plain text HTML using only pure JavaScript.

How to add elements to the DOM given plain text HTML using only pure JavaScript?

To add elements to the DOM given plain text HTML using only pure JavaScript, we call the insertAdjancentHTML methods.

For instance, we write

document.body.insertAdjacentHTML("beforeend", theHTMLToInsert);

to call document.body.insertAdjacentHTML to insert the content of the theHTMLToInsert before the end of the body element.

Conclusion

To add elements to the DOM given plain text HTML using only pure JavaScript, we call the insertAdjancentHTML methods.