web api interface
Range
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 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.
Constructor
Instance properties
Also inherits properties from its parent interface, AbstractRange.
commonAncestorContainerRead only- : Returns the deepest
Nodethat contains thestartContainerandendContainernodes.
- : Returns the deepest
Instance methods
There are no inherited methods.
collapse()- : Collapses the
Rangeto one of its boundary points.
- : Collapses the
compareBoundaryPoints()- : Compares the boundary points of the
Rangewith anotherRange.
- : Compares the boundary points of the
compareNode()Deprecated- : Returns a constant representing whether the
Nodeis before, after, inside, or surrounding the range.
- : Returns a constant representing whether the
comparePoint()- : Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the
Range.
- : Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the
cloneContents()- : Returns a
DocumentFragmentcopying the nodes of aRange.
- : Returns a
cloneRange()- : Returns a
Rangeobject with boundary points identical to the clonedRange.
- : Returns a
createContextualFragment()- : Returns a
DocumentFragmentcreated from a given string of code.
- : Returns a
deleteContents()- : Removes the contents of a
Rangefrom theDocument.
- : Removes the contents of a
detach()Deprecated- : Does nothing. Kept for compatibility.
extractContents()- : Moves contents of a
Rangefrom the document tree into aDocumentFragment.
- : Moves contents of a
getBoundingClientRect()- : Returns a
DOMRectobject which bounds the entire contents of theRange; this would be the union of all the rectangles returned bygetClientRects().
- : Returns a
getClientRects()- : Returns a list of
DOMRectobjects that aggregates the results ofgetClientRects()for all the elements in theRange.
- : Returns a list of
isPointInRange()- : Returns a
booleanindicating whether the given point is in theRange.
- : Returns a
insertNode()- : Insert a
Nodeat the start of aRange.
- : Insert a
intersectsNode()- : Returns a
booleanindicating whether the given node intersects theRange.
- : Returns a
selectNode()- : Sets the
Rangeto contain theNodeand its contents.
- : Sets the
selectNodeContents()- : Sets the
Rangeto contain the contents of aNode.
- : Sets the
setEnd()- : Sets the end position of a
Range.
- : Sets the end position of a
setStart()- : Sets the start position of a
Range.
- : Sets the start position of a
setEndAfter()- : Sets the end position of a
Rangerelative to anotherNode.
- : Sets the end position of a
setEndBefore()- : Sets the end position of a
Rangerelative to anotherNode.
- : Sets the end position of a
setStartAfter()- : Sets the start position of a
Rangerelative to anotherNode.
- : Sets the start position of a
setStartBefore()- : Sets the start position of a
Rangerelative to anotherNode.
- : Sets the start position of a
surroundContents()- : Moves content of a
Rangeinto a newNode.
- : Moves content of a
toString()- : Returns the text of the
Range.
- : Returns the text of the
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.