Interface Selection
anchorNode: Node | null;
anchorOffset: number;
direction: string;
focusNode: Node | null;
focusOffset: number;
isCollapsed: boolean;
rangeCount: number;
type: string;
addRange(range: Range): void;
collapse(node: Node | null, offset?: number): void;
collapseToEnd(): void;
collapseToStart(): void;
containsNode(node: Node, allowPartialContainment?: boolean): boolean;
deleteFromDocument(): void;
empty(): void;
extend(node: Node, offset?: number): void;
getComposedRanges(options?: GetComposedRangesOptions): StaticRange[];
getRangeAt(index: number): Range;
modify(alter?: string, direction?: string, granularity?: string): void;
removeAllRanges(): void;
removeRange(range: Range): void;
selectAllChildren(node: Node): void;
setBaseAndExtent(
anchorNode: Node,
anchorOffset: number,
focusNode: Node,
focusOffset: number,
): void;
setPosition(node: Node | null, offset?: number): void;
toString(): string;
}
Index
Properties
Methods
Properties
ReadonlyanchorNode
The Selection.anchorNode read-only property returns the Node in which the selection begins.
ReadonlyanchorOffset
The Selection.anchorOffset read-only property returns the number of characters that the selection's anchor is offset within the In the case of Selection.anchorNode being another type of node, Selection.anchorOffset returns the number of Node.childNodes the selection's anchor is offset within the Selection.anchorNode.
Readonlydirection
The direction read-only property of the Selection interface is a string that provides the direction of the current selection.
ReadonlyfocusNode
The Selection.focusNode read-only property returns the Node in which the selection ends.
ReadonlyfocusOffset
The Selection.focusOffset read-only property returns the number of characters that the selection's focus is offset within the In the case of Selection.focusNode being another type of node, Selection.focusOffset returns the number of Node.childNodes the selection's focus is offset within the Selection.focusNode.
ReadonlyisCollapsed
The Selection.isCollapsed read-only property returns a boolean value which indicates whether or not there is currently any text selected.
ReadonlyrangeCount
The Selection.rangeCount read-only property returns the number of ranges in the selection.
Readonlytype
The type read-only property of the type of the current selection.
Methods
addRange
The
Selection.addRange()method adds ajs-nolint addRange(range)-range- : A Range object that will be added to the Selection.Parameters
- range: Range
Returns void
collapse
The
Selection.collapse()method collapses the current selection to a single point.Parameters
- node: Node | null
Optionaloffset: number
Returns void
collapseToEnd
The
Selection.collapseToEnd()method collapses the selection to the end of the last range in the selection.Returns void
collapseToStart
The
Selection.collapseToStart()method collapses the selection to the start of the first range in the selection.Returns void
containsNode
The
Selection.containsNode()method indicates whether a specified node is part of the selection.Parameters
- node: Node
OptionalallowPartialContainment: boolean
Returns boolean
deleteFromDocument
The
deleteFromDocument()method of thejs-nolint deleteFromDocument()None.Returns void
empty
The
Selection.empty()method removes all ranges from the selection, leaving the Selection.anchorNode and Selection.focusNode properties equal tonulland nothing selected.Returns void
extend
The
Selection.extend()method moves the focus of the selection to a specified point.Parameters
- node: Node
Optionaloffset: number
Returns void
getComposedRanges
The
Selection.getComposedRanges()method returns an array of StaticRange objects representing the current selection ranges, and can return ranges that potentially cross shadow boundaries.Parameters
Optionaloptions: GetComposedRangesOptions
Returns StaticRange[]
getRangeAt
The
getRangeAt()method of the Selection interface returns a range object representing a currently selected range.Parameters
- index: number
Returns Range
modify
The
Selection.modify()method applies a change to the current selection or cursor position, using simple textual commands.Parameters
Optionalalter: stringOptionaldirection: stringOptionalgranularity: string
Returns void
removeAllRanges
The
Selection.removeAllRanges()method removes all ranges from the selection, leaving the Selection.anchorNode and Selection.focusNode properties equal tonulland nothing selected.Returns void
removeRange
The
Selection.removeRange()method removes a range from a selection.Parameters
- range: Range
Returns void
selectAllChildren
The
Selection.selectAllChildren()method adds all the children of the specified node to the selection.Parameters
- node: Node
Returns void
setBaseAndExtent
setPosition
The
Selection.setPosition()method collapses the current selection to a single point.Parameters
- node: Node | null
Optionaloffset: number
Returns void
toString
Returns string
A
Selectionobject represents the range of text selected by the user or the current position of the caret.MDN Reference