setSelectionRange method

void setSelectionRange(
  1. int start,
  2. int end, [
  3. String direction
])

The HTMLInputElement.setSelectionRange() method sets the start and end positions of the current text selection in an input or textarea element.

The element must be focused for the call to have any effect.

Optionally, you can specify the direction in which selection should be considered to have occurred. This lets you indicate, for example, that the selection was set by the user clicking and dragging from the end of the selected text toward the beginning.

This method updates the HTMLInputElement.selectionStart, HTMLInputElement.selectionEnd, and HTMLInputElement.selectionDirection properties in one call.

The element must be of one of the following input types: password, search, tel, text, or url. Otherwise the browser throws an InvalidStateError exception.

If you wish to select all text of an input element, you can use the HTMLInputElement.select() method instead.

Implementation

external void setSelectionRange(
  int start,
  int end, [
  String direction,
]);