Range: deleteContents() method

The Range.deleteContents() method removes the contents of the Range from the Document.

In the context of a Range, when a node is partially selected—meaning it overlaps with the start or end of the selection—only the selected portion of the text is deleted, while the node itself remains intact. However, if a node is fully selected, the entire node and its contents are removed.

Unlike Range.extractContents(), this method does not return a DocumentFragment containing the deleted content.

Syntax

js
deleteContents()

Parameters

None.

Return value

None (undefined).

Examples

js
range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
range.deleteContents();

Specifications

Specification
DOM Standard
# dom-range-deletecontents

Browser compatibility

BCD tables only load in the browser

See also