Web/API/Range

From Get docs

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 the startContainer and endContainer nodes.
Range.endContainer Read only
Returns the Node within which the Range ends.
Range.endOffset Read only
Returns a number representing where in the endContainer the Range ends.
Range.startContainer Read only
Returns the Node within which the Range starts.
Range.startOffset Read only
Returns a number representing where in the startContainer the Range starts.

Constructor

Range() '
Returns a Range object with the global Document as its start and end.

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 another Node.
Range.setStartAfter()
Sets the start position of a Range relative to another Node.
Range.setEndBefore()
Sets the end position of a Range relative to another Node.
Range.setEndAfter()
Sets the end position of a Range relative to another Node.
Range.selectNode()
Sets the Range to contain the Node and its contents.
Range.selectNodeContents()
Sets the Range to contain the contents of a Node.
Range.collapse()
Collapses the Range to one of its boundary points.
Range.cloneContents()
Returns a DocumentFragment copying the nodes of a Range.
Range.deleteContents()
Removes the contents of a Range from the Document.
Range.extractContents()
Moves contents of a Range from the document tree into a DocumentFragment.
Range.insertNode()
Insert a Node at the start of a Range.
Range.surroundContents()
Moves content of a Range into a new Node.
Range.compareBoundaryPoints()
Compares the boundary points of the Range with another Range.
Range.cloneRange()
Returns a Range object with boundary points identical to the cloned Range.
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 the Range; this would be the union of all the rectangles returned by range.getClientRects().
Range.getClientRects() '
Returns a list of DOMRect objects that aggregates the results of Element.getClientRects() for all the elements in the Range.
Range.intersectsNode() '
Returns a boolean indicating whether the given node intersects the Range.
Range.isPointInRange() '
Returns a boolean indicating whether the given point is in the Range.

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 collapse() optional. Added the methods isPointInRange(), comparePoint(), and intersectsNode(). Added the constructor Range().

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

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Range Chrome

Full support 1

Edge

Full support 12

Firefox Full support 4

Notes'

Full support 4

Notes'

Notes' Starting with Firefox 13, the Range object throws a DOMException as defined in DOM 4, instead of a RangeException defined in prior specifications.

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

Notes'

Full support 4

Notes'

Notes' Starting with Firefox 13, the Range object throws a DOMException as defined in DOM 4, instead of a RangeException defined in prior specifications.

Opera Android

Full support 10.1

Safari iOS

Full support 1

Samsung Internet Android

Full support 1.0

Range() constructor

Experimental'

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

compareNode

Experimental'Deprecated'Non-standard'

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

comparePoint

Experimental'

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

createContextualFragment

Experimental'

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

Notes'

Full support Yes

Notes'

Notes' Since April 2014 this method is a no-op in Chrome.

Edge

Full support 12

Firefox No support 4 — 15

Notes'

No support 4 — 15

Notes'

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

Notes'

Full support Yes

Notes'

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

Notes'

No support 4 — 15

Notes'

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

Notes'

Full support Yes

Notes'

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

getBoundingClientRect

Experimental'

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

getClientRects

Experimental'

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

intersectsNode

Experimental'

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

isPointInRange

Experimental'

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.