Range
The Range interface represents a fragment of a document that can contain nodes and parts of text nodes.
Documentation Range by Mozilla Contributors, licensed under CC-BY-SA 2.5.
Static Members
START_TO_START: IntSTART_TO_END: IntEND_TO_END: IntEND_TO_START: IntInstance Members
startContainer: NodeReturns the Node within which the Range starts.
startOffset: IntReturns a number representing where in the startContainer the Range starts.
endContainer: NodeReturns the Node within which the Range ends.
endOffset: IntReturns a number representing where in the endContainer the Range ends.
collapsed: BoolReturns a Boolean indicating whether the range's start and end points are at the same position.
commonAncestorContainer: NodeReturns the deepest Node that contains the startContainer and endContainer nodes.
Sets the start position of a Range.
| Name | Type |
|---|---|
refNode |
Node |
offset |
Int |
Sets the end position of a Range.
| Name | Type |
|---|---|
refNode |
Node |
offset |
Int |
Sets the start position of a Range relative to another Node.
| Name | Type |
|---|---|
refNode |
Node |
Sets the start position of a Range relative to another Node.
| Name | Type |
|---|---|
refNode |
Node |
Sets the end position of a Range relative to another Node.
| Name | Type |
|---|---|
refNode |
Node |
Sets the end position of a Range relative to another Node.
| Name | Type |
|---|---|
refNode |
Node |
Collapses the Range to one of its boundary points.
| Name | Type | Default |
|---|---|---|
toStart |
Bool | false |
Sets the Range to contain the Node and its contents.
| Name | Type |
|---|---|
refNode |
Node |
Sets the Range to contain the contents of a Node.
| Name | Type |
|---|---|
refNode |
Node |
Compares the boundary points of the Range with another Range.
| Name | Type |
|---|---|
how |
Int |
sourceRange |
Range |
| Returns |
|---|
| Int |
deleteContents(): VoidRemoves the contents of a Range from the Document.
extractContents(): DocumentFragmentMoves contents of a Range from the document tree into a DocumentFragment.
| Returns |
|---|
| DocumentFragment |
cloneContents(): DocumentFragmentReturns a DocumentFragment copying the nodes of a Range.
| Returns |
|---|
| DocumentFragment |
Insert a Node at the start of a Range.
| Name | Type |
|---|---|
node |
Node |
Moves content of a Range into a new Node.
| Name | Type |
|---|---|
newParent |
Node |
cloneRange(): RangeReturns a Range object with boundary points identical to the cloned Range.
| Returns |
|---|
| Range |
detach(): VoidReleases the Range from use to improve performance.
Returns a boolean indicating whether the given point is in the Range.
| Name | Type |
|---|---|
node |
Node |
offset |
Int |
| Returns |
|---|
| Bool |
Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the Range.
| Name | Type |
|---|---|
node |
Node |
offset |
Int |
| Returns |
|---|
| Int |
Returns a boolean indicating whether the given node intersects the Range.
| Name | Type |
|---|---|
node |
Node |
| Returns |
|---|
| Bool |
createContextualFragment(fragment: String): DocumentFragmentReturns a DocumentFragment created from a given string of code.
| Name | Type |
|---|---|
fragment |
String |
| Returns |
|---|
| DocumentFragment |
getClientRects(): DOMRectListReturns a list of DOMRect objects that aggregates the results of Element.getClientRects() for all the elements in the Range.
| Returns |
|---|
| DOMRectList |
getBoundingClientRect(): DOMRectReturns a DOMRect object which bounds the entire contents of the Range; this would be the union of all the rectangles returned by range.getClientRects().
| Returns |
|---|
| DOMRect |
new(): Void