In a simple webapp, I have a text area with some text, when user highligh a word in the text area, then click a button to process the word, the handler failed to get the highlighted word.
<input type="button" value="click" onclick="handle()"><input>
<textarea> </textarea>
<script>
function handle() {
alert(window.getSelection().toString());
}
</script>
Any idea how to do this?
Thanks
UPDATE1
When I run window.getSelection().toString()
in Chrome developer console, it does give the highlighted text, however, when I click a button. it returned nothing. I guess clicking will de-highlight the highlighted text.