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.
Properties
There are no inherited properties.
Range.collapsed
Read only- Returns a
Boolean
indicating whether the range's start and end points are at the same position. Range.commonAncestorContainer
Read only- Returns the deepest
Node
that contains thestartContainer
andendContainer
nodes. Range.endContainer
Read only- Returns the
Node
within which theRange
ends. Range.endOffset
Read only- Returns a number representing where in the
endContainer
theRange
ends. Range.startContainer
Read only- Returns the
Node
within which theRange
starts. Range.startOffset
Read only- Returns a number representing where in the
startContainer
theRange
starts.
Constructor
Methods
There are no inherited methods.
Range.setStart()
- Sets the start position of a
Range
. Range.setEnd()
- Sets the end position of a
Range
. Range.setStartBefore()
- Sets the start position of a
Range
relative to anotherNode
. Range.setStartAfter()
- Sets the start position of a
Range
relative to anotherNode
. Range.setEndBefore()
- Sets the end position of a
Range
relative to anotherNode
. Range.setEndAfter()
- Sets the end position of a
Range
relative to anotherNode
. Range.selectNode()
- Sets the
Range
to contain theNode
and its contents. Range.selectNodeContents()
- Sets the
Range
to contain the contents of aNode
. Range.collapse()
- Collapses the
Range
to one of its boundary points. Range.cloneContents()
- Returns a
DocumentFragment
copying the nodes of aRange
. Range.deleteContents()
- Removes the contents of a
Range
from theDocument
. Range.extractContents()
- Moves contents of a
Range
from the document tree into aDocumentFragment
. Range.insertNode()
- Insert a
Node
at the start of aRange
. Range.surroundContents()
- Moves content of a
Range
into a newNode
. Range.compareBoundaryPoints()
- Compares the boundary points of the
Range
with anotherRange
. Range.cloneRange()
- Returns a
Range
object with boundary points identical to the clonedRange
. Range.detach()
- Releases the
Range
from use to improve performance. Range.toString()
- Returns the text of the
Range
. Range.compareNode()
' '- Returns a constant representing whether the
Node
is 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.createContextualFragment()
'- Returns a
DocumentFragment
created from a given string of code. Range.getBoundingClientRect()
'- Returns a
DOMRect
object 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
DOMRect
objects that aggregates the results ofElement.getClientRects()
for all the elements in theRange
. Range.intersectsNode()
'- Returns a
boolean
indicating whether the given node intersects theRange
. Range.isPointInRange()
'- Returns a
boolean
indicating whether the given point is in theRange
.
Specifications
Specification | Status | Comment |
---|---|---|
DOMThe definition of 'Range' in that specification. | Living Standard | Do not use RangeException anymore, use DOMException instead.
Made the second parameter of |
DOM Parsing and SerializationThe definition of 'Extensions to Range' in that specification. | Working Draft | Added the method createContextualFragment() .
|
CSS Object Model (CSSOM) View ModuleThe 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 SpecificationThe definition of 'Range' in that specification. | Obsolete | Initial specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Range
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox Full support 4 Full support 4 Notes' Starting with Firefox 13, the |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support 1 |
WebView Android
Full support 1 |
Chrome Android
Full support 18 |
Firefox Android Full support 4 Full support 4 Notes' Starting with Firefox 13, the |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
Chrome
Full support Yes |
Edge
Full support ≤18 |
Firefox
Full support 24 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 24 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes | |
cloneContents
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
cloneRange
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
collapse
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
collapsed
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
commonAncestorContainer
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
compareBoundaryPoints
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No | |
Chrome
Full support Yes |
Edge
Full support 17 |
Firefox
Full support Yes |
IE
No support No |
Opera
Full support 15 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes | |
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support Yes |
IE
Full support 11 |
Opera
Full support 15 |
Safari
Full support 9 |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes | |
deleteContents
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
detach
|
Chrome Full support Yes Full support Yes Notes' Since April 2014 this method is a no-op in Chrome. |
Edge
Full support 12 |
Firefox No support 4 — 15 No support 4 — 15 Notes' Starting in Firefox 15.0, this method is a no-op and has no effect. |
IE
Full support 9 |
Opera
Full support 9 |
Safari Full support Yes Full support Yes Notes' Since August 2015 this method is a no-op in WebKit-based browsers. |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android No support 4 — 15 No support 4 — 15 Notes' Starting in Firefox 15.0, this method is a no-op and has no effect. |
Opera Android
Full support Yes |
Safari iOS Full support Yes Full support Yes Notes' Since August 2015 this method is a no-op in WebKit-based browsers. |
Samsung Internet Android
Full support Yes |
endContainer
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
endOffset
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
extractContents
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 15 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes | |
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 15 |
Safari
Full support 5 |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes | |
insertNode
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support 10.1 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Chrome
Full support Yes |
Edge
Full support 17 |
Firefox
Full support 17 |
IE
No support No |
Opera
Full support 15 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 19 |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes | |
Chrome
Full support Yes |
Edge
Full support 15 |
Firefox
Full support Yes |
IE
No support No |
Opera
Full support 15 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support 14 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes | |
selectNode
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
selectNodeContents
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
setEnd
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
setEndAfter
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
setEndBefore
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
setStart
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
setStartAfter
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
setStartBefore
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
startContainer
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
startOffset
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
surroundContents
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
toString
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 9 |
Opera
Full support 9 |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
- Non-standard. Expect poor cross-browser support.'
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.'
- Deprecated. Not for use in new websites.
- See implementation notes.'
- See implementation notes.
See also
Range by Mozilla Contributors is licensed under CC-BY-SA 2.5.