I tried the jquery-fieldselection plugin to get the selected text in textarea.
It works fine in Firefox and Chrome, but not in Internet Explorer 7.
I use the getSelection() method like this:
textarea.getSelection();
When the text within the textarea is 12345, and all this text is selected, Firefox and Chrome returns:
start: 0 // Correct!
end: 5
while Internet Explorer 7 returns:
start: 5 // Why ??
end: 5
I’m looking for a cross browser solution using jQuery.
just took a look a tthelibrary and it behaves differently for IE since it does not support some methods that the modern browsers do.. may be the code there isnt perfect..
use the following method:
how to use it:
you need the dom object of the textarea.. thus:
Live Demo