.selection()
.selection() function can be applied to an input text field or text area elements. This function will return selected text, start and end index.
If nothing is selected, cursor position will be returned.
Returns
Example 1
Select some text and click on "Show Selection" to see the selected text, starting and ending index.
JS
HTML
CSS
$.domLoaded(function() { $.get("#btn1").on("click", function() { //Get selection from text field var res = $.get("#inp").selection(); alert("Selected Text : " + res.text + "\nStart : " + res.start + "\nEnd : " + res.end); }); });
Result
| |||||