MDN self-hosted library · e01.org

HTMLTextAreaElement: setSelectionRange() method

HTML DOM

no runnable cells web-api-instance-method upstream source

HTML DOM

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 selectionStart property.
  • 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 selectionEnd is less than selectionStart, then both are treated as the value of selectionEnd. See the selectionEnd property.
  • selectionDirection
  • : A string indicating the direction in which the selection is considered to have been performed. See the selectionDirection property. Possible values:
    • "forward"
    • "backward"
    • "none" if the direction is unknown or irrelevant. Default value.

Return value

None (undefined).

Specifications

Browser compatibility

See also

  • textarea
  • HTMLTextAreaElement
  • Selection