DOM Element.remove() Method
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
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.
Desktop





Tablets & Mobile





