Skip to content
Advertisement

What is the difference between insertAdjacentHtml and insertAdjacentElement?

What is the main difference between element and html? I used
insertAdjacentElement('beforeend', html);
and it showed error. But worked when using
insertAdjacentHTML('beforeend', html);
Just wondering what the difference was.

Advertisement

Answer

insertAdjacentElement() is used to insert an element which is already in the Dom. You can get this element with getElementById() for example. https://www.w3schools.com/jsref/met_node_insertadjacentelement.asp

insertAdjacentHtml() is used to insert html code. https://www.w3schools.com/jsref/met_node_insertadjacenthtml.asp

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement