How to remove an element from the DOM with vanilla JS
Node.remove() method lets you remove an element from the DOM. Call it on the element you want to remove.
For example, let’s say you had a heading and paragraph, like this.
<h1>Hello, world!</h1> <p>How are you today?</p>
To remove the
h1 element, you would do this.
let h1 = document.querySelector('h1'); h1.remove();