HTMLTextAreaElement: setSelectionRange() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The setSelectionRange() method of the HTMLTextAreaElement interface sets the start and end positions of the current text selection in a <textarea> element.
For general information about this method, see HTMLInputElement.setSelectionRange().
Syntax
setSelectionRange(selectionStart, selectionEnd)
setSelectionRange(selectionStart, selectionEnd, selectionDirection)
Parameters
selectionStart-
The 0-based index of the first selected character. An index greater than the length of the element's value is treated as pointing to the end of the value. See the
selectionStartproperty. selectionEnd-
The 0-based index of the character after the last selected character. An index greater than the length of the element's value is treated as pointing to the end of the value. If
selectionEndis less thanselectionStart, then both are treated as the value ofselectionEnd. See theselectionEndproperty. selectionDirectionOptional-
A string indicating the direction in which the selection is considered to have been performed. See the
selectionDirectionproperty. Possible values:"forward""backward""none"if the direction is unknown or irrelevant. Default value.
Return value
None (undefined).
Specifications
| Specification |
|---|
| HTML> # dom-textarea/input-setselectionrange-dev> |