Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between insertAdjacentHtml and insertAdjacentElement?

Tags:

javascript

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.

like image 384
Sack32 Avatar asked Mar 13 '26 02:03

Sack32


1 Answers

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

like image 196
Colin Faivre Avatar answered Mar 15 '26 14:03

Colin Faivre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!