The goog.dom.selection Namespace

.getEnd(textfield)

Returns the place where the selection ends inside a textarea or a text input

textfield {Element}
A textarea or text input.
returns {number}
The position where the selection ends or 0 if it was unable to find the position or no selection exists.

.getEndPoints(textfield)

Returns the start and end points of the selection inside a textarea or a text input.

textfield {Element}
A textarea or text input.
returns {Array.<number>}
An array with the start and end positions where the selection starts and ends or [0,0] if it was unable to find the positions or no selection exists. Note that we can't reliably tell the difference between an element that has no selection and one where it starts and ends at 0.

.getStart(textfield)

Return the place where the selection starts inside a textarea or a text input

textfield {Element}
A textarea or text input.
returns {number}
The position where the selection starts or 0 if it was unable to find the position or no selection exists. Note that we can't reliably tell the difference between an element that has no selection and one where it starts at 0.

.getText(textfield)

Returns the selected text inside a textarea or a text input

textfield {Element}
A textarea or text input.
returns {string}
The selected text.

.setCursorPosition(textfield, pos)

Sets the cursor position within a textfield.

textfield {Element}
A textarea or text input.
pos {number}
The position within the text field.

.setEnd(textfield, pos)

Sets the place where the selection should end inside a text area or a text input

textfield {Element}
A textarea or text input.
pos {number}
The position to end the selection at.

.setStart(textfield, pos)

Sets the place where the selection should start inside a textarea or a text input

textfield {Element}
A textarea or text input.
pos {number}
The position to set the start of the selection at.

.setText(textfield, text)

Sets the selected text inside a textarea or a text input

textfield {Element}
A textarea or text input.
text {string}
The text to change the selection to.