public interface Range
The Range
object represents a fragment of a document that can contain nodes and parts of text nodes in a given document.
A range can be created using the Document.createRange
method of the Document
object. Range objects can also be retrieved by using the Selection.getRangeAt
method of the Selection
object.
Modifier and Type | Field and Description |
---|---|
static int |
END_TO_END |
static int |
END_TO_START |
static int |
NODE_AFTER |
static int |
NODE_BEFORE |
static int |
NODE_BEFORE_AND_AFTER |
static int |
NODE_INSIDE |
static int |
START_TO_END |
static int |
START_TO_START |
Modifier and Type | Method and Description |
---|---|
DocumentFragment |
cloneContents()
Returns a
DocumentFragment
copying the nodes of a Range. |
Range |
cloneRange()
Returns a Range object with boundary points identical to the cloned Range.
|
void |
collapse(boolean toStart)
Collapses the Range to one of its boundary points.
|
short |
compareNode(Node refNode)
Returns a constant representing whether the Node is before, after, inside, or surrounding the range.
|
short |
comparePoint(Node refNode,
int offset)
Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the range.
|
DocumentFragment |
createContextualFragment(String html)
Returns a
DocumentFragment
created from a given string of code. |
void |
deleteContents()
Removes the contents of a Range from the
Document
. |
void |
detach()
Releases Range from use to improve performance.
|
void |
expand(String unit) |
DocumentFragment |
extractContents()
Moves contents of a Range from the document tree into a
DocumentFragment
. |
ClientRect |
getBoundingClientRect()
Returns a
ClientRect
object which bounds the entire contents of the range; this would be the union of all the rectangles returned by range.getClientRects()
. |
ClientRectList |
getClientRects()
Returns a list of
ClientRect
objects that aggregates the results of Element.getClientRects()
for all the elements in the range. |
Node |
getCommonAncestorContainer()
Returns the deepest
Node
that contains the startContainer and endContainer Nodes. |
Node |
getEndContainer()
Returns the
Node
within which the Range ends. |
int |
getEndOffset()
Returns a number representing where in the endContainer the Range ends.
|
Node |
getStartContainer()
Returns the
Node
within which the Range starts. |
int |
getStartOffset()
Returns a number representing where in the startContainer the Range starts.
|
void |
insertNode(Node newNode)
Insert a
Node
at the start of a Range. |
boolean |
intersectsNode(Node refNode)
Returns a
boolean indicating whether the given node intersects the range. |
boolean |
isCollapsed()
Returns a
boolean indicating whether the range's start and end points are at the same position. |
boolean |
isPointInRange(Node refNode,
int offset)
Returns a
boolean indicating whether the given point is in the range. |
void |
selectNode(Node refNode)
Sets the Range to contain the
Node
and its contents. |
void |
selectNodeContents(Node refNode)
Sets the Range to contain the contents of a
Node
. |
void |
setEnd(Node refNode,
int offset)
Sets the end position of a Range.
|
void |
setEndAfter(Node refNode)
Sets the end position of a Range relative to another
Node
. |
void |
setEndBefore(Node refNode)
Sets the end position of a Range relative to another
Node
. |
void |
setStart(Node refNode,
int offset)
Sets the start position of a Range.
|
void |
setStartAfter(Node refNode)
Sets the start position of a Range relative to another
Node
. |
void |
setStartBefore(Node refNode)
Sets the start position of a Range relative to another
Node
. |
void |
surroundContents(Node newParent)
Moves content of a Range into a new
Node
. |
static final int END_TO_END
static final int END_TO_START
static final int NODE_AFTER
static final int NODE_BEFORE
static final int NODE_BEFORE_AND_AFTER
static final int NODE_INSIDE
static final int START_TO_END
static final int START_TO_START
boolean isCollapsed()
boolean
indicating whether the range's start and end points are at the same position.Node getCommonAncestorContainer()
Node
that contains the startContainer and endContainer Nodes.int getEndOffset()
int getStartOffset()
DocumentFragment cloneContents()
DocumentFragment
copying the nodes of a Range.Range cloneRange()
void collapse(boolean toStart)
short compareNode(Node refNode)
short comparePoint(Node refNode, int offset)
DocumentFragment createContextualFragment(String html)
DocumentFragment
created from a given string of code.void deleteContents()
Document
.void detach()
void expand(String unit)
DocumentFragment extractContents()
DocumentFragment
.ClientRect getBoundingClientRect()
ClientRect
object which bounds the entire contents of the range; this would be the union of all the rectangles returned by range.getClientRects()
.ClientRectList getClientRects()
ClientRect
objects that aggregates the results of Element.getClientRects()
for all the elements in the range.boolean intersectsNode(Node refNode)
boolean
indicating whether the given node intersects the range.boolean isPointInRange(Node refNode, int offset)
boolean
indicating whether the given point is in the range.void selectNodeContents(Node refNode)
Node
.void setEnd(Node refNode, int offset)
void setEndAfter(Node refNode)
Node
.void setEndBefore(Node refNode)
Node
.void setStart(Node refNode, int offset)
void setStartAfter(Node refNode)
Node
.void setStartBefore(Node refNode)
Node
.Copyright © 2016. All rights reserved.