Javascript / Jquery: How To Get Selected Text In Firefox
How can I get the selected text (in a contenteditable div) in Firefox ? It would be enough for recent versions, no need to cover old versions. Say I have a contenteditable div that
Solution 1:
var selectedText = "" + window.getSelection();
Solution 2:
The other suggestions didn't work for me, but the following did:
var textArea = document.getElementById('input_text_area');
var selectedText = textArea.value.substring(textArea.selectionStart,textArea.selectionEnd);
This other answer links to some background on why the above is necessary and why window.getSelection() doesn't work on Firefox, for example.
Post a Comment for "Javascript / Jquery: How To Get Selected Text In Firefox"