Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I deselect text using Javascript or jQuery?

I have a draggable (jQuery UI) element with "canceled" text on it. Here's what I mean:

$('#main').draggable({
        cancel: '#main>* *',
        start: function(){
          // deselect text
        }
});

When I drag the element, I often select the text by accident. I want to deselect the text when the element is dragged.

like image 980
Leo Jiang Avatar asked Dec 30 '11 22:12

Leo Jiang


People also ask

How to deselect text in textbox using jQuery?

$('#main'). draggable({ cancel: '#main>* *', start: function(){ // deselect text } });


1 Answers

To deselect everything you can use:

document.getSelection().removeAllRanges();
like image 150
Eric G Avatar answered Oct 13 '22 06:10

Eric G