--- title: Range slug: Web/API/Range tags: - API - DOM - NeedsTranslation - TopicStub translation_of: Web/API/Range ---
{{ APIRef("DOM") }}
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 {{ domxref("Document.createRange", "createRange()") }} method of the {{ domxref("Document") }} object. Range objects can also be retrieved by using the {{ domxref("Selection/getRangeAt", "getRangeAt()") }} method of the {{ domxref("Selection") }} object or the {{domxref("Document/caretRangeFromPoint", "caretRangeAtPoint()")}} method of the {{domxref("Document")}} object.
There also is the {{domxref("Range.Range()", "Range()")}} constructor available.
There are no inherited properties.
startContainer
and endContainer
nodes.Range
ends.endContainer
the Range
ends.Range
starts.startContainer
the Range
starts.Range
object with the global {{domxref("Document")}} as its start and end.There are no inherited methods.
Range
.Range
.Range
relative to another {{ domxref("Node") }}.Range
relative to another {{ domxref("Node") }}.Range
relative to another {{ domxref("Node") }}.Range
relative to another {{ domxref("Node") }}.Range
to contain the {{ domxref("Node") }} and its contents.Range
to contain the contents of a {{ domxref("Node") }}.Range
to one of its boundary points.Range
.Range
from the {{ domxref("Document") }}.Range
from the document tree into a {{ domxref("DocumentFragment") }}.Range
.Range
into a new {{ domxref("Node") }}.Range
with another Range
.Range
object with boundary points identical to the cloned Range
.Range
from use to improve performance.Range
.Range
.Range
; this would be the union of all the rectangles returned by {{ domxref("range.getClientRects()") }}.Range
.boolean
indicating whether the given node intersects the Range
.boolean
indicating whether the given point is in the Range
.Specification | Status | Comment |
---|---|---|
{{SpecName('DOM WHATWG', '#interface-range', 'Range')}} | {{Spec2('DOM WHATWG')}} | 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() . |
{{SpecName('DOM Parsing', '#extensions-to-the-range-interface', 'Extensions to Range')}} | {{Spec2('DOM Parsing')}} | Added the method createContextualFragment() . |
{{SpecName('CSSOM View', '#extensions-to-the-range-interface', 'Extensions to Range')}} | {{Spec2('CSSOM View')}} | Added the methods getClientRects() and getBoundingClientRect() . |
{{SpecName('DOM2 Traversal_Range', 'ranges.html#Level-2-Range-Interface', 'Range')}} | {{Spec2('DOM2 Traversal_Range')}} | Initial specification. |
{{CompatibilityTable}}
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.0")}} [1] | 9.0 | 9.0 | {{CompatVersionUnknown}} |
Range() constructor {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatGeckoDesktop("24.0")}} | {{CompatNo}} | 15.0 | {{CompatVersionUnknown}} |
compareNode() {{obsolete_inline}}{{non-standard_inline()}} |
{{CompatNo}} | {{CompatUnknown}} | {{CompatGeckoDesktop("1.0")}} Removed in {{CompatGeckoDesktop("1.9")}} |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
isPointInRange() , and comparePoint() {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatNo}} | 15.0 | {{CompatUnknown}} |
intersectsNode() {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatGeckoDesktop("17.0")}} [2] | {{CompatNo}} | 15.0 | {{CompatUnknown}} |
getClientRects() and getBoundingClientRect() {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("2.0")}} | 9 | 15.0 | 5 |
createContextualFragment() {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | 11 | 15.0 | {{CompatUnknown}} |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.0")}} [1] | 9.0 | 9.0 | {{CompatVersionUnknown}} |
[1] Starting with Gecko 13.0 {{ geckoRelease("13.0") }} the Range
object throws a {{ domxref("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.