The DOM StaticRange interface extends AbstractRange to provide a method to specify a range of content in the DOM whose contents don't update to reflect changes which occur within the DOM tree. It offers the same set of properties and methods as AbstractRange.
AbstractRange and StaticRange are not available from web workers.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="/docs/Web/API/AbstractRange" target="_top"><rect x="1" y="1" width="130" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="66" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">AbstractRange</text></a><polyline points="131,25 141,20 141,30 131,25" stroke="#D4DDE4" fill="none"/><line x1="141" y1="25" x2="171" y2="25" stroke="#D4DDE4"/><a xlink:href="/docs/Web/API/StaticRange" target="_top"><rect x="171" y="1" width="110" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="226" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">StaticRange</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Constructor
StaticRange()- Creates a new
StaticRangeobject given theStaticRangeInitdictionary specifying the default values for its properties.
Properties
The properties below are inherited from its parent interface, AbstractRange.
StaticRange.collapsedRead only- Returns a Boolean value which is
trueif the range's start and end positions are the same, resulting in a range of length 0. StaticRange.endContainerRead only- Returns the DOM
Nodewhich contains the ending point of the range. The offset into the node at which the end position is located is indicated byendOffset. StaticRange.endOffsetRead only- Returns an integer value indicating the offset into the node given by
endContainerat which the last character of the range is found. StaticRange.startContainerRead only- Returns the DOM
Nodewhich contains the starting point of the range (which is in turn identified bystartOffset. StaticRange.startOffsetRead only- Returns an integer value indicating the offset into the node specified by
startContainerat which the first character of the range is located.
Methods
StaticRange.toRange()- Returns a new
Rangeobject which describes the same range as the sourceStaticRange, but is "live" with values that change to reflect changes in the contents of the DOM tree.
Usage notes
A DOM range specifies a span of content in a document, potentially beginning inside one node (or element) and ending inside another one. Unlike a Range, a StaticRange represents a range which is fixed in time; it does not change to try to keep the same content within it as the document changes. If any changes are made to the DOM, the actual data contained within the range specified by a StaticRange may change. This lets the user agent avoid a lot of work that is unnecessary if the web app or site doesn't need a live-updating range.
Specifications
| Specification | Status | Comment |
|---|---|---|
| DOM The definition of 'StaticRange' in that specification. |
Living Standard | |
| Static Range The definition of 'StaticRange' in that specification. |
Editor's Draft | Initial definition. |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
StaticRange | Chrome Full support 60 | Edge Full support 18 | Firefox
Full support
69
| IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 |
StaticRange() constructor | Chrome No support No | Edge No support No | Firefox Full support 71 | IE No support No | Opera No support No | Safari Full support 13.1 | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS Full support 13.4 | Samsung Internet Android No support No |
collapsed | Chrome Full support 60 | Edge Full support 18 | Firefox Full support 69 | IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 |
endContainer | Chrome Full support 60 | Edge Full support 18 | Firefox Full support 69 | IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 |
endOffset | Chrome Full support 60 | Edge Full support 18 | Firefox Full support 69 | IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 |
startContainer | Chrome Full support 60 | Edge Full support 18 | Firefox Full support 69 | IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 |
startOffset | Chrome Full support 60 | Edge Full support 18 | Firefox Full support 69 | IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 |
toRange() | Chrome Full support 60 | Edge Full support 18 | Firefox No support No | IE No support No | Opera Full support 47 | Safari No support No | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android No support No | Opera Android Full support 44 | Safari iOS No support No | Samsung Internet Android Full support 8.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.
See also
- Live updating range of content within the DOM:
Range AbstractRange, the abstract interface from which all ranges are derived
