To append HTML to container element without innerHTML with JavaScript, we call the insertAdjacentHTML
method.
For instance, we write
const d1 = document.getElementById("one");
d1.insertAdjacentHTML("beforeend", '<div id="two">two</div>');
to select the container element with getElementById
.
And then we call insertAdjacentHTML
method with 'beforeend'
and a string with the element to insert.
'beforeend'
inserts the HTML as the last child of the container element.