Selection extension type
A Selection
object represents the range of text selected by the user
or the current position of the caret. To obtain a Selection
object for
examination or manipulation, call window.getSelection
.
A user may make a selection from left to right (in document order) or right to left (reverse of document order). The anchor is where the user began the selection and the focus is where the user ends the selection. If you make a selection with a desktop mouse, the anchor is placed where you pressed the mouse button, and the focus is placed where you released the mouse button.
Note: Anchor and focus should not be confused with the start and end positions of a selection. The anchor can be placed before the focus or vice versa, depending on the direction you made your selection.
- on
- Implemented types
- Available extensions
Properties
- anchorNode → Node?
-
no setter
- anchorOffset → int
-
no setter
- direction → String
-
no setter
- focusNode → Node?
-
no setter
- focusOffset → int
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isCollapsed → bool
-
no setter
- rangeCount → int
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type → String
-
no setter
Methods
-
addRange(
Range range) → void -
The
Selection.addRange()
method adds a Range to a Selection. -
collapse(
Node? node, [int offset]) → void -
The
Selection.collapse()
method collapses the current selection to a single point. The document is not modified. If the content is focused and editable, the caret will blink there. -
collapseToEnd(
) → void -
The
Selection.collapseToEnd()
method collapses the selection to the end of the last range in the selection. If the content of the selection is focused and editable, the caret will blink there. -
collapseToStart(
) → void -
The
Selection.collapseToStart()
method collapses the selection to the start of the first range in the selection. If the content of the selection is focused and editable, the caret will blink there. -
containsNode(
Node node, [bool allowPartialContainment]) → bool -
The
Selection.containsNode()
method indicates whether a specified node is part of the selection. -
deleteFromDocument(
) → void -
The
deleteFromDocument()
method of the Selection interface deletes the selected text from the document's DOM. -
empty(
) → void -
The
Selection.empty()
method removes all ranges from the selection, leaving the Selection.anchorNode and Selection.focusNode properties equal tonull
and nothing selected. When this method is called, aDocument/selectionchange_event
event is fired at the document. -
extend(
Node node, [int offset]) → void -
The
Selection.extend()
method moves the focus of the selection to a specified point. The anchor of the selection does not move. The selection will be from the anchor to the new focus, regardless of direction. -
getComposedRanges(
ShadowRoot shadowRoots) → JSArray< StaticRange> -
getRangeAt(
int index) → Range -
The
Selection.getRangeAt()
method returns a range object representing one of the ranges currently selected. -
modify(
[String alter, String direction, String granularity]) → void -
The
Selection.modify()
method applies a change to the current selection or cursor position, using simple textual commands. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeAllRanges(
) → void -
The
Selection.removeAllRanges()
method removes all ranges from the selection, leaving the Selection.anchorNode and Selection.focusNode properties equal tonull
and nothing selected. When this method is called, aDocument/selectionchange_event
event is fired at the document. -
removeRange(
Range range) → void -
The
Selection.removeRange()
method removes a range from a selection. -
selectAllChildren(
Node node) → void -
The
Selection.selectAllChildren()
method adds all the children of the specified node to the selection. Previous selection is lost. -
setBaseAndExtent(
Node anchorNode, int anchorOffset, Node focusNode, int focusOffset) → void -
The
setBaseAndExtent()
method of the Selection interface sets the selection to be a range including all or parts of two specified DOM nodes, and any content located between them. -
setPosition(
Node? node, [int offset]) → void -
The
Selection.setPosition()
method collapses the current selection to a single point. The document is not modified. If the content is focused and editable, the caret will blink there. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited