StaticRange: StaticRange() constructor
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
TheStaticRange() constructorcreates a newStaticRange object representing a span of content withinthe DOM.
This constructor includes properties identifying the start and end positions ofthe range as well as a Boolean indicating whether or not the range iscollapsed (that is, empty).
In this article
Syntax
new StaticRange(rangeSpec)Parameters
rangeSpecThe required
rangeSpecparameter is an objectcontaining the four following properties:startContainerThe
Nodein which the starting point of the range is located.startOffsetThe offset into the starting node at which the first character of the range isfound.
endContainerThe
Nodein which the end point of the range is located.endOffsetThe offset into the node indicated by
endOffsetat which the lastcharacter in the range is located.
Return value
A newStaticRange object initialized with the values given intherangeSpec object.
Exceptions
InvalidNodeTypeErrorA
DOMExceptionfired if either or both of thestartContainerand/orendContainerare a type of node whichyou can't include in a range. Those node typesareNode.DOCUMENT_TYPE_NODE(representing theDocumentTypenode derived from theDTD identified using thedoctypepreamble in the HTML, for example) and theAttrnode describing anattribute of an element on the DOM.
Specifications
| Specification |
|---|
| DOM> # ref-for-dom-staticrange-staticrange①> |