Categories
JavaScript Answers

How to append HTML string to the DOM with JavaScript?

Spread the love

Sometimes, we want to append HTML string to the DOM with JavaScript.

In this article, we’ll look at how to append HTML string to the DOM with JavaScript.

How to append HTML string to the DOM with JavaScript?

To append HTML string to the DOM with JavaScript, we can use the insertAdjacentHTML method.

For instance, we write

div.insertAdjacentHTML("beforeend", str);

to call div.insertAdjacentHTML with 'beforeend' and str to append the content of str to the end of the div.

Conclusion

To append HTML string to the DOM with JavaScript, we can use the insertAdjacentHTML method.

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 *