Issue
I want to detect if text is highlighted in a textarea only, not the whole document. window.getSelection() works, but I don't want to grab text from any other part of the document that could be highlighted, just what's in the text area.
Basically, I'm trying to do this:
if (document.getElementById("mytextarea").getSelection) {
//do stuff
}
What would be the easiest way to accomplish this? Thanks!
Solution
this should work (assuming by highlighted you mean selected)
var textarea = document.getElementById("tarea");
var selection = (textarea.value).substring(textarea.selectionStart,textarea.selectionEnd);
console.log(selection);
<textarea id="tarea"></textarea>
Answered By - user6057915
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.