Categories
JavaScript Answers

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

Spread the love

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.

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 *