Element.prototype.removeChild
Removes a child node from the DOM and returns the removed node
Syntax
element.removeChild(child)Parameters
| Parameter | Type | Description |
|---|---|---|
| child | Node | The child node to be removed |
Return Value
The removed child node
Examples
const list = document.querySelector('ul')!
const firstItem = list.firstElementChild
if (firstItem) list.removeChild(firstItem)const parent = document.getElementById('container')!
while (parent.firstChild) {
parent.removeChild(parent.firstChild)
}function removeLastChild(parent: HTMLElement) {
const last = parent.lastElementChild
if (last) return parent.removeChild(last)
return null
}Understanding Element.prototype.removeChild
The Element.prototype.removeChild method in JavaScript removes a child node from the DOM and returns the removed node. 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.removeChild(child). It accepts 1 parameter: child. When called, it returns the removed child node. Understanding when and how to use removeChild() helps you write more expressive, readable code.
Common use cases for Element.prototype.removeChild include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like dom-remove, dom-replacechild, dom-appendchild, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Element.prototype.removeChild 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.removeRemoves the element from the DOM tree it belongs to
Element.prototype.replaceChildReplaces a child node within the given parent node with a new node
Element.prototype.appendChildAdds a node to the end of the list of children of a specified parent node
Element.prototype.insertBeforeInserts a node before a reference node as a child 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.