Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Element.remove(): detaching an element

The element.remove() method detaches an element from its parent. It takes no arguments, returns undefined, and does nothing when the element has no parent.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

element.remove()

Element.remove denotes the instance method element.remove(), provided through the ChildNode mixin. It is a DOM API, not a function defined by ECMAScript.

The method detaches the element and its subtree from its parent. A retained reference still points to the same object; it can be inserted again. Without a parent, the call does nothing.

Unlike parent.removeChild(element), this method needs no parent reference and returns undefined, not the removed node. The example uses a detached tree: the element need not belong to the document.

Examples

const parent = document.createElement('div');
const element = document.createElement('span');
parent.appendChild(element);

console.log(parent.childNodes.length);
const result = element.remove();
console.log(parent.childNodes.length);
console.log(element.parentNode === null);
console.log(result === undefined);
element.remove();
console.log(parent.childNodes.length);

Result

1
0
true
true
0

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources