Sometimes, we want to append HTML to container element without innerHTML with JavaScript.
In this article, we’ll look at how to append HTML to container element without innerHTML with JavaScript.
How to append HTML to container element without innerHTML with JavaScript?
To append HTML to container element without innerHTML with JavaScript, we can use ther insertAdjacentHTML
method.
For instance, we write
const d1 = document.getElementById("one");
d1.insertAdjacentHTML("beforeend", '<div id="two">two</div>');
to select the element we want to insert a sibling element besides.
Then we call insertAdjacentHTML
with 'beforeend'
and the string with the HTML we want to insert to put the element after the last child.
Conclusion
To append HTML to container element without innerHTML with JavaScript, we can use ther insertAdjacentHTML
method.