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
The Get Selected Text function below returns a 3 part array:
- The selected text.
- The start position of the selected text.
- 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: