Javascript Code Function to Get/Replace the Selected Text

Javascript Code Function to Get the Selected Text, the Start and End Position of the Selected Text and Optionally Replace the Selected Text. This will Work to Get the Selected Text in a Textarea, Div, Input and ANY Text Selected in an HTML Document

Home Short:

The Get Selected Text function below returns a 3 part array:

  1. The selected text.
  2. The start position of the selected text.
  3. The end position of the selected text.

This function also allows you to replace the selected text. Here is an example of how to do that:

S
H
A
R
E