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: Int
START_TO_END: Int
END_TO_END: Int
END_TO_START: Int
Instance Members
startContainer: Node
Returns the Node
within which the Range
starts.
startOffset: Int
Returns a number representing where in the startContainer
the Range
starts.
endContainer: Node
Returns the Node
within which the Range
ends.
endOffset: Int
Returns a number representing where in the endContainer
the Range
ends.
collapsed: Bool
Returns a Boolean
indicating whether the range's start and end points are at the same position.
commonAncestorContainer: Node
Returns 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(): Void
Removes the contents of a Range
from the Document
.
extractContents(): DocumentFragment
Moves contents of a Range
from the document tree into a DocumentFragment
.
Returns |
---|
DocumentFragment |
cloneContents(): DocumentFragment
Returns 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(): Range
Returns a Range
object with boundary points identical to the cloned Range
.
Returns |
---|
Range |
detach(): Void
Releases 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): DocumentFragment
Returns a DocumentFragment
created from a given string of code.
Name | Type |
---|---|
fragment |
String |
Returns |
---|
DocumentFragment |
getClientRects(): DOMRectList
Returns a list of DOMRect
objects that aggregates the results of Element.getClientRects()
for all the elements in the Range
.
Returns |
---|
DOMRectList |
getBoundingClientRect(): DOMRect
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()
.
Returns |
---|
DOMRect |
new(): Void