Range
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The Range interface represents a fragment of a document that can contain nodes and parts of text nodes.
A range can be created by using the Document.createRange() method. Range objects can also be retrieved by using the getRangeAt() method of the Selection object or the caretRangeFromPoint() method of the Document object.
There also is the Range() constructor available.
Instance properties
There are no inherited properties.
Range.collapsedRead only-
Returns a boolean value indicating whether the range's start and end points are at the same position.
Range.commonAncestorContainerRead only-
Returns the deepest
Nodethat contains thestartContainerandendContainernodes. Range.endContainerRead only-
Returns the
Nodewithin which theRangeends. Range.endOffsetRead only-
Returns a number representing where in the
endContainertheRangeends. Range.startContainerRead only-
Returns the
Nodewithin which theRangestarts. Range.startOffsetRead only-
Returns a number representing where in the
startContainertheRangestarts.
Constructor
Instance methods
There are no inherited methods.
Range.collapse()-
Collapses the
Rangeto one of its boundary points. Range.compareBoundaryPoints()-
Compares the boundary points of the
Rangewith anotherRange. Range.compareNode()Deprecated Non-standard-
Returns a constant representing whether the
Nodeis before, after, inside, or surrounding the range. Range.comparePoint()-
Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the
Range. Range.cloneContents()-
Returns a
DocumentFragmentcopying the nodes of aRange. Range.cloneRange()-
Returns a
Rangeobject with boundary points identical to the clonedRange. Range.createContextualFragment()-
Returns a
DocumentFragmentcreated from a given string of code. Range.deleteContents()-
Removes the contents of a
Rangefrom theDocument. Range.detach()-
Does nothing. Kept for compatibility.
Range.extractContents()-
Moves contents of a
Rangefrom the document tree into aDocumentFragment. Range.getBoundingClientRect()-
Returns a
DOMRectobject which bounds the entire contents of theRange; this would be the union of all the rectangles returned byrange.getClientRects(). Range.getClientRects()-
Returns a list of
DOMRectobjects that aggregates the results ofElement.getClientRects()for all the elements in theRange. Range.isPointInRange()-
Returns a
booleanindicating whether the given point is in theRange. Range.insertNode()-
Insert a
Nodeat the start of aRange. Range.intersectsNode()-
Returns a
booleanindicating whether the given node intersects theRange. Range.selectNode()-
Sets the
Rangeto contain theNodeand its contents. Range.selectNodeContents()-
Sets the
Rangeto contain the contents of aNode. Range.setEnd()-
Sets the end position of a
Range. Range.setStart()-
Sets the start position of a
Range. Range.setEndAfter()-
Sets the end position of a
Rangerelative to anotherNode. Range.setEndBefore()-
Sets the end position of a
Rangerelative to anotherNode. Range.setStartAfter()-
Sets the start position of a
Rangerelative to anotherNode. Range.setStartBefore()-
Sets the start position of a
Rangerelative to anotherNode. Range.surroundContents()-
Moves content of a
Rangeinto a newNode. Range.toString()-
Returns the text of the
Range.
Specifications
| Specification |
|---|
| DOM> # interface-range> |
| DOM Parsing and Serialization> # extensions-to-the-range-interface> |
| CSSOM View Module> # extensions-to-the-range-interface> |
Browser compatibility
Loading…