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.