Selection: removeRange() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2023.
The Selection.removeRange() method removes a range from a
selection.
Syntax
js
removeRange(range)
Parameters
range-
A range object that will be removed from the selection.
Return value
None (undefined).
Examples
js
/* Programmatically, more than one range can be selected.
* This will remove all ranges except the first. */
const s = window.getSelection();
if (s.rangeCount > 1) {
for (let i = 1; i < s.rangeCount; i++) {
s.removeRange(s.getRangeAt(i));
}
}
Specifications
| Specification |
|---|
| Selection API> # dom-selection-removerange> |
Browser compatibility
See also
Selection, the interface it belongs to.