The Range
interface represents a fragment of a document that can contain nodes and parts of text nodes.
A range can be created using the createRange()
method of the Document
object. Range objects can also be retrieved by using the getRangeAt()
method of the Selection
object or the caretRangeAtPoint()
method of the Document
object.
There also is the Range()
constructor available.
There are no inherited properties.
Range.collapsed
Read only
Boolean
indicating whether the range's start and end points are at the same position.Range.commonAncestorContainer
Read only
Node
that contains the startContainer
and endContainer
nodes.Range.endContainer
Read only
Node
within which the Range
ends.Range.endOffset
Read only
endContainer
the Range
ends.Range.startContainer
Read only
Node
within which the Range
starts.Range.startOffset
Read only
startContainer
the Range
starts.There are no inherited methods.
Range.setStart()
Range
.Range.setEnd()
Range
.Range.setStartBefore()
Range
relative to another Node
.Range.setStartAfter()
Range
relative to another Node
.Range.setEndBefore()
Range
relative to another Node
.Range.setEndAfter()
Range
relative to another Node
.Range.selectNode()
Range
to contain the Node
and its contents.Range.selectNodeContents()
Range
to contain the contents of a Node
.Range.collapse()
Range
to one of its boundary points.Range.cloneContents()
DocumentFragment
copying the nodes of a Range
.Range.deleteContents()
Range
from the Document
.Range.extractContents()
Range
from the document tree into a DocumentFragment
.Range.insertNode()
Node
at the start of a Range
.Range.surroundContents()
Range
into a new Node
.Range.compareBoundaryPoints()
Range
with another Range
.Range.cloneRange()
Range
object with boundary points identical to the cloned Range
.Range.detach()
Range
from use to improve performance.Range.toString()
Range
.Range.compareNode()
Node
is before, after, inside, or surrounding the range.Range.comparePoint()
Range
.Range.createContextualFragment()
DocumentFragment
created from a given string of code.Range.getBoundingClientRect()
ClientRect
object which bounds the entire contents of the Range
; this would be the union of all the rectangles returned by range.getClientRects()
.Range.getClientRects()
ClientRect
objects that aggregates the results of Element.getClientRects()
for all the elements in the Range
.Range.intersectsNode()
boolean
indicating whether the given node intersects the Range
.Range.isPointInRange()
boolean
indicating whether the given point is in the Range
.Specification | Status | Comment |
---|---|---|
DOM The definition of 'Range' in that specification. | Living Standard | Do not use RangeException anymore, use DOMException instead.Made the second parameter of collapse() optional.Added the methods isPointInRange() , comparePoint() , and intersectsNode() .Added the constructor Range() . |
DOM Parsing and Serialization The definition of 'Extensions to Range' in that specification. | Working Draft | Added the method createContextualFragment() . |
CSS Object Model (CSSOM) View Module The definition of 'Extensions to Range' in that specification. | Working Draft | Added the methods getClientRects() and getBoundingClientRect() . |
Document Object Model (DOM) Level 2 Traversal and Range Specification The definition of 'Range' in that specification. | Recommendation | Initial specification. |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 1.0 (1.7 or earlier) [1] | 9.0 | 9.0 | (Yes) |
Range() constructor
| (Yes) | ? | 24.0 (24.0) | No support | 15.0 | (Yes) |
compareNode()
| No support | ? | 1.0 (1.7 or earlier) Removed in 3.0 (1.9) | No support | No support | No support |
isPointInRange() , and comparePoint()
| (Yes) | ? | (Yes) | No support | 15.0 | ? |
intersectsNode()
| (Yes) | ? | 17.0 (17.0) [2] | No support | 15.0 | ? |
getClientRects() and getBoundingClientRect()
| (Yes) | (Yes) | 4.0 (2.0) | 9 | 15.0 | 5 |
createContextualFragment()
| (Yes) | ? | (Yes) | 11 | 15.0 | ? |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 1.0 (1.0) [1] | 9.0 | 9.0 | (Yes) |
[1] Starting with Gecko 13.0 (Firefox 13.0 / Thunderbird 13.0 / SeaMonkey 2.10) the Range
object throws a DOMException
as defined in DOM 4, instead of a RangeException
defined in prior specifications.
[2] Gecko supported it up to Gecko 1.9, then removed it until Gecko 17 where it was reimplemented, matching the spec.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Range