Range: deleteContents() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

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

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
deleteContents

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also