Reputation: 3667
I have an html file that displays some text. I need to call a JavaScript function when the user selects some text on it. I have the following code but the highlightSelection()
function never gets called.
window.onselect = highlightSelection;
function highlightSelection() {
}
Is there any other way to call a JS function while user selects some text?
Upvotes: 2
Views: 267
Reputation: 36
you need to put the text in the appropriate element, an example:
<input type="text" value="This is some selectable text" onselect="showMsg()" />
function showMsg(){
}
Upvotes: 2