Element.prototype.remove
Removes the element from the DOM tree it belongs to
Syntax
element.remove()Return Value
undefined
Examples
const el = document.querySelector('.old-banner')
el?.remove()document.querySelectorAll('.temp').forEach(el => el.remove())function removeById(id: string) {
const el = document.getElementById(id)
if (el) {
el.remove()
return true
}
return false
}Understanding Element.prototype.remove
The Element.prototype.remove method in JavaScript removes the element from the DOM tree it belongs to. It belongs to the Element object and is one of the most widely used methods for working with element values in modern JavaScript and TypeScript applications.
The method signature is element.remove(). When called, it returns undefined. Understanding when and how to use remove() helps you write more expressive, readable code.
Common use cases for Element.prototype.remove include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like dom-removechild, dom-replacewith, dom-appendchild, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Element.prototype.remove is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Element.prototype.removeChildRemoves a child node from the DOM and returns the removed node
Element.prototype.replaceWithReplaces this Element in the children list of its parent with a set of Node or string objects
Element.prototype.appendChildAdds a node to the end of the list of children of a specified parent node
More Element Methods
Other methods in the Element object
Related Tools
More Element Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.