Object: Selection
The Selection object contains one or more Range objects.
Selection properties
Property name |
Type |
Description |
Status |
Availability |
|---|---|---|---|---|
anchorNode |
Returns the node in which the selection begins. |
read-only |
4.7.1 or later |
|
anchorOffset |
int |
Returns the number of characters within the anchorNode that the selection begins. |
read-only |
4.7.1 or later |
focusNode |
Returns the node in which the selection ends. |
read-only |
4.7.1 or later |
|
focusOffset |
int |
Returns the number of characters within the focusNode that the selection ends. |
read-only |
4.7.1 or later |
isCollapsed |
boolean |
Returns true if the start point and end point of the selection are at the same position; returns false if they are not. |
read-only |
4.7.1 or later |
rangeCount |
int |
Returns the number of Range objects contained by the Selection object. |
read-only |
4.7.1 or later |
Selection methods
Method name |
Description |
Availability |
|---|---|---|
Adds a Range object to the selection. |
4.7.1 or later |
|
Collapses a selection onto a single boundary point. |
4.7.1 or later |
|
Moves the anchor of the selection to the same point as the focus. |
4.7.1 or later |
|
Moves the focus of the selection to the same point as the anchor. |
4.7.1 or later |
|
Deletes the text contained within the selection from the Document object. |
4.7.1 or later |
|
Returns a Range object that is present in the selection. |
4.7.1 or later |
|
Removes the specified Range object from the selection. |
4.7.1 or later |
|
Removes all Range objects from the selection. |
4.7.1 or later |
|
Adds all the child nodes of a specified node to the selection. |
4.7.1 or later |
Method: Selection.addRange()
Method: Selection.collapseToEnd()
Method: Selection.collapseToStart()
Method: Selection.collapse()
Parameters
Parameter |
Type |
Description |
|---|---|---|
parentNode |
Specifies the node into which the selection is collapsed. |
|
offset |
int |
Specifies the offset to which the selection is collapsed. Valid values may be one of the following: 0: Collapses the selection from the anchor onto the start point of parentNode. 1: Collapses the selection from the anchor onto the end point of parentNode. |
Method: Selection.deleteFromDocument()
The deleteFromDocument() method deletes the text contained within the selection from the Document object.
Method: Selection.getRangeAt()
The getRangeAt() method returns a Range object that is present in the selection.
Parameters
Parameter |
Type |
Description |
|---|---|---|
index |
int |
Specifies an integer that represents the Range object’s position in the frame map. Valid values are from 0 to Selection.rangeCount-1. |
Method: Selection.removeAllRanges()
The removeAllRanges() method removes all Range objects from the selection.
Method: Selection.removeRange()
The removeRange() method removes the specified Range object from the selection.
Method: Selection.selectAllChildren()
The selectAllChildren() method adds all the child nodes from a specified node to the selection. If the selection is already populated, the contents are replaced.