How to remove an HTML element in JavaScript?

To remove an HTML element in JavaScript, call element.remove().

So if this is your element:

<div id="my-element"></div>

Then you can remove it with this JavaScript:

document.getElementById("my-element").remove();