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 call the insertAdjacentHTML
method.
For instance, we write
div.insertAdjacentHTML("beforeend", str);
to call the div.insertAdjacentHTML
to append the HTML string str
‘s content after its last child of the div
.
Conclusion
To append HTML string to the DOM with JavaScript, we call the insertAdjacentHTML
method.