Returns the Node
in which the selection begins. Can return null
if selection never existed in the document (e.g., an iframe that was never clicked on).
SuperNode
Returns a number representing the offset of the selection's anchor within the anchorNode
. If anchorNode
is a text node, this is the number of characters within anchorNode preceding the anchor. If anchorNode
is an element, this is the number of child nodes of the anchorNode
preceding the anchor.
Promise<number>
Returns the Node
in which the selection ends. Can return null
if selection never existed in the document (for example, in an iframe
that was never clicked on).
SuperNode
Returns a number representing the offset of the selection's anchor within the focusNode
. If focusNode
is a text node, this is the number of characters within focusNode
preceding the focus. If focusNode
is an element, this is the number of child nodes of the focusNode
preceding the focus.
Promise<number>
Returns a Boolean indicating whether the selection's start and end points are at the same position.
Promise<boolean>
Returns the number of ranges in the selection.
Promise<number>
Returns a string
describing the type of the current selection.
Promise<string>
A Range
object that will be added to the selection.
Range
. A Range
object that will be added to the Selection
.Promise<void>
Collapses the current selection to a single point.
Node
. The caret location will be within this node. This value can also be set to null
— if null
is specified, the method will behave like Selection.removeAllRanges()
, i.e. all ranges will be removed from the selection.number
. The offset in node
to which the selection will be collapsed. If not specified, the default value 0
is used.Promise<void>
Collapses the selection to the end of the last range in the selection.
Promise<void>
Collapses the selection to the start of the first range in the selection.
Promise<void>
Indicates if a certain node is part of the selection.
Node
. The node that is being looked for in the selection.boolean
. When true
, containsNode()
returns true
when a part of the node is part of the selection. When false
, containsNode()
only returns true
when the entire node is part of the selection. If not specified, the default value false
is used.Promise<boolean>
Deletes the selection's content from the document.
Promise<void>
Removes all ranges from the selection. This is an alias for removeAllRanges()
— See Selection.removeAllRanges()
for more details.
Promise<void>
Moves the focus of the selection to a specified point.
Node
. The node within which the focus will be moved.number
. The offset position within node
where the focus will be moved to. If not specified, the default value 0
is used.Promise<void>
Returns a Range
object representing one of the ranges currently selected.
number
. The zero-based index of the range to return. A negative number or a number greater than or equal to Selection.rangeCount
will result in an error.Range
Changes the current selection.
string
. The type of change to apply. Specify "move"
to move the current cursor position or "extend"
to extend the current selection.string
. The direction in which to adjust the current selection. You can specify "forward"
or "backward"
to adjust in the appropriate direction based on the language at the selection point. If you want to adjust in a specific direction, you can specify "left"
or "right"
.string
. The distance to adjust the current selection or cursor position. You can move by "character"
, "word"
, "sentence"
, "line"
, "paragraph"
, "lineboundary"
, "sentenceboundary"
, "paragraphboundary"
, or "documentboundary"
.Promise<void>
Removes all ranges from the selection.
Promise<void>
Removes a range from the selection.
Range
. A range object that will be removed to the selection.Promise<void>
Adds all the children of the specified node to the selection.
Node
. All children of parentNode
will be selected. parentNode
itself is not part of the selection.Promise<void>
Sets the selection to be a range including all or parts of two specified DOM nodes, and any content located between them.
Node
. The node at the start of the selection.number
. The number of child nodes from the start of the anchor node that should be excluded from the selection. So for example, if the value is 0 the whole node is included. If the value is 1, the whole node minus the first child node is included. And so on.Node
. The node at the end of the selection.number
. The number of child nodes from the start of the focus node that should be included in the selection. So for example, if the value is 0 the whole node is excluded. If the value is 1, the first child node is included. And so on.Promise<void>
Collapses the current selection to a single point. This is an alias for collapse()
— See Selection.collapse()
for more details.
Node
. Needs content.number
. Needs content.Promise<void>
Returns a string currently being represented by the selection object, i.e. the currently selected text.
Promise<string>