Deselect when user double click anywhere using jQuery

As you know, when the user double-clicks , Explorer tries to select the nearest objects (for example, text, a row table, etc.), as shown in the figure below: enter image description here

User can:

  • select any text with one click

User cannot

  • select any object with a double click (in other words, when the user double-clicks on the list, jquery should cancel the selection)

So how can I do this? Hope this is understandable.

Note. I use the double-click operation to enter an item.

+4
source share
2 answers

I forgot that this is one of those cases when the default action cannot be undone in the event. In this case, you can use the CSS approach for Firefox and Chrome:

-moz-user-select: none; -webkit-user-select: none; 

And for Opera / IE:

 $("#mytable td").prop("unselectable", "on"); // jQuery 1.6+ $("#mytable td").attr("unselectable", "on"); // jQuery 1.5- 

If you want the user to still be able to drag and drop, you can work in this solution:

 $("#mytable td").bind("dblclick", function () { var $this = $(this); $this.prop("unselectable", "on").css({ "moz-user-select" : "none", "-webkit-user-select" : "none" }); window.setTimeout(function () { var $this = $(this); $this.prop("unselectable", "").css({ "moz-user-select" : "", "-webkit-user-select" : "" }); }, 0); }); 
+5
source

select some random item and

 $("#randsmallelement").focus(); 

If this does not work, try adding

 $("#randsmallelement).select(); 
0
source

All Articles