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 modification, call window.getSelection()
.
Documentation Selection by Mozilla Contributors, licensed under CC-BY-SA 2.5.
See also:
Variables
read onlyanchorOffset:Int
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.
read onlyfocusOffset:Int
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.
read onlyisCollapsed:Bool
Returns a Boolean indicating whether the selection's start and end points are at the same position.
Methods
collapse(node:Node, offset:Int = 0):Void
Collapses the current selection to a single point.
Throws:
null | DOMError |
---|
collapseToEnd():Void
Collapses the selection to the end of the last range in the selection.
Throws:
null | DOMError |
---|
collapseToStart():Void
Collapses the selection to the start of the first range in the selection.
Throws:
null | DOMError |
---|
containsNode(node:Node, allowPartialContainment:Bool = false):Bool
Indicates if a certain node is part of the selection.
Throws:
null | DOMError |
---|
extend(node:Node, offset:Int = 0):Void
Moves the focus of the selection to a specified point.
Throws:
null | DOMError |
---|
getRangeAt(index:Int):Range
modify(alter:String, direction:String, granularity:String):Void
Changes the current selection.
Throws:
null | DOMError |
---|
selectAllChildren(node:Node):Void
Adds all the children of the specified node to the selection.
Throws:
null | DOMError |
---|