Question

I'm trying to find a way to determine that some selected text has been unselected.

I've tried using the isCollapsed property of window.getSelection(), however if you click inside the text range to clear the text selection it still reports as false. If you click outside the text range to clear the selection it reports as true.

This fiddle demonstrates what I'm talking about.

What else can I use to determine some selected text has been unselected?

I only need this to work in Chrome.

Thanks

Was it helpful?

Solution

How about using a timeout of 10ms

$(function() {
    $("#select").on('mouseup keyup', function() {
        setTimeout(function(){
        var sel = window.getSelection();
        console.log(sel.isCollapsed);
        },10);
    });
}); 

FIDDLE LINK

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top