Favorites

DOM Element.remove() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Element.remove()
DOM Element MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The remove() method removes an element from the page.

Description

The remove() method removes the element from its parent, and so from the page. It doesn't need a reference to the parent, unlike removeChild(). The element still exists in memory while your code holds a reference, and can be inserted again.

Calling it on an element that isn't in the page does nothing, so there's no need to check first. Removing an element also removes everything inside it. Event listeners attached to it aren't removed, but they're garbage-collected along with the element once nothing else refers to it.

remove() is defined on elements, text nodes and comments, but not on the document itself. Removing a focused element moves focus back to the body, so move focus somewhere sensible first, such as a nearby control.

Syntax

element.remove()

Return Value

None (undefined).

Example

<div id="note">Cookie notice <button id="close" type="button">Close</button></div>
const note = document.getElementById('note');
document.getElementById('close').addEventListener('click', () => {
  note.remove();
  console.log('Removed. Still in page?', document.body.contains(note));
});
document.getElementById('close').click();

Browser Support

The following information will show you the current browser support for the Element.remove() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee