Answer the question
In order to leave comments, you need to log in
How to call alert () when the selection (slection) disappears from the text?
Hello!
Can you please tell me how to trigger an event, in this case any alert(), when the selection disappears from the text?
It is this event that is needed, not click or something else.
I will be grateful for help.
Answer the question
In order to leave comments, you need to log in
It is possible like this:
var prevSelection;
document.addEventListener('mouseup', function() {
var selection;
if (window.getSelection) {
selection = window.getSelection().toString();
} else if (document.selection) {
selection = document.selection.createRange().text;
}
if (!selection && prevSelection.length) {
alert('Text uselected');
}
prevSelection = selection;
});
I won’t tell you much, but I dug up this information, it can give you ideas: selectiononchange event , and select event . I wish you success in your decision.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question