insertAdjacentHTML() is a built-in JavaScript DOM method that allows you to insert HTML content into a document at a specific position relative to an existing element without removing existing elements or event handlers.
insertAdjacentHTML()
It is a safer and more performant alternative to innerHTML in most real-world applications.
innerHTML
element.insertAdjacentHTML(position, htmlString);
Use only trusted server content
Or sanitize before inserting
Or use DOM creation methods