Selection

@native @JSGlobal @JSType
class Selection extends Object

Selection is the class of the object returned by window.getSelection() and other methods. It represents the text selection in the greater page, possibly spanning multiple elements, when the user drags over static text and other parts of the page. For information about text selection in an individual text editing element, see Input, TextArea and document.activeElement which typically return the parent object returned from window.getSelection().

class Object
trait Any
class Object
trait Matchable
class Any

Value members

Concrete methods

def addRange(range: Range): Unit

A range object that will be added to the selection.

A range object that will be added to the selection.

Returns the node in which the selection begins.

Returns the node in which the selection begins.

def anchorOffset: 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.

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.

def collapse(parentNode: Node, offset: Int): Unit

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.

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.

def collapseToEnd(): Unit

Collapses the selection to the end of the last range in the selection.  If the content the selection is in is focused and editable, the caret will blink there.

Collapses the selection to the end of the last range in the selection.  If the content the selection is in is focused and editable, the caret will blink there.

def collapseToStart(): Unit

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.

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.

def containsNode(node: Node, partialContainment: Boolean): Boolean

Indicates if the node is part of the selection

Indicates if the node is part of the selection

def deleteFromDocument(): Unit

Deletes the actual text being represented by a selection object from the document's DOM.

Deletes the actual text being represented by a selection object from the document's DOM.

def extend(node: Node, offset: Int): Unit

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.

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.

Returns the node in which the selection ends.

Returns the node in which the selection ends.

def focusOffset: 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.

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.

def getRangeAt(index: Int): Range

Returns a range object representing one of the ranges currently selected.

Returns a range object representing one of the ranges currently selected.

def isCollapsed: Boolean

Returns a boolean indicating whether the selection's start and end points are at the same position.

Returns a boolean indicating whether the selection's start and end points are at the same position.

def rangeCount: Int

Returns the number of ranges in the selection.

Returns the number of ranges in the selection.

def removeAllRanges(): Unit

Removes all ranges from the selection, leaving the anchorNode and focusNode properties equal to null and leaving nothing selected.

Removes all ranges from the selection, leaving the anchorNode and focusNode properties equal to null and leaving nothing selected.

def removeRange(range: Range): Unit

Removes a range from the selection.

Removes a range from the selection.

def selectAllChildren(parentNode: Node): Unit

Adds all the children of the specified node to the selection. Previous selection is lost.

Adds all the children of the specified node to the selection. Previous selection is lost.

Inherited methods

def hasOwnProperty(v: String): Boolean
Inherited from:
Object
def isPrototypeOf(v: Object): Boolean
Inherited from:
Object
def propertyIsEnumerable(v: String): Boolean
Inherited from:
Object
def toLocaleString(): String
Inherited from:
Object
def valueOf(): Any
Inherited from:
Object