Element

Element.prototype.removeChild

Removes a child node from the DOM and returns the removed node

Syntax

JavaScript
element.removeChild(child)

Parameters

ParameterTypeDescription
childNodeThe child node to be removed

Return Value

The removed child node

Examples

Basic Usage
const list = document.querySelector('ul')!
const firstItem = list.firstElementChild
if (firstItem) list.removeChild(firstItem)
Practical Example
const parent = document.getElementById('container')!
while (parent.firstChild) {
  parent.removeChild(parent.firstChild)
}
Advanced Usage
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

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.