Selection Class
Normalizes text selection functionality across browsers.
Constructor
Selection
()
Methods
range
-
[index=0]
Returns the Range
instance at the specified index, or the first range in
this selection if no index is specified. If no ranges are selected, returns
null
.
Parameters:
-
[index=0]
Number optionalRange index.
Returns:
Range instance at the specified index, or the first range
in this selection if no index is specified. If no ranges are selected,
returns null
.
ranges
()
Range[]
Returns an array containing all the ranges in this selection.
Returns:
Array containing all the ranges in this selection.
select
-
range
-
[options]
Selects the specified range.
By default, this will result in only this range being selected. If
options.multi
is truthy, then the range will be added to the current
selection without first unselecting any other selected ranges.
toString
()
String
Returns a string representation of the combined text content of all the ranges in this selection.
Returns:
String representation of the combined text content of all the ranges in this selection.
unselect
-
[range]
Removes the specified range from this selection, or unselects all ranges if no range is specified.
Parameters:
-
[range]
Range optionalRange to unselect.