How to Remove Elements from the DOM with ES6 JavaScript

With ES6 JavaScript it’s easy to remove elements from the DOM. You simply attach the remove() method to the element you want to remove:

let element = document.querySelector("element-to-remove")
element.remove()

For example if you want to remove the h1 element from a web page:

let headingOne = document.querySelector("h1")
headingOne.remove()

The remove() method is compatible with all modern browsers, including Edge. It’s not compatible with any Internet Explorer browser, including IE11.

Source: Caniuse.com


Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on