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

Était-ce utile?

La 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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top