I'm handling the dblclick event on a span in my web app. A side-effect is that the double click selects text on the page. How can I prevent this selection from happening?
Select the text that you want to remove highlighting from, or press Ctrl+A to select all of the text in the document. Go to Home and select the arrow next to Text Highlight Color. Select No Color.
function clearSelection() {     if(document.selection && document.selection.empty) {         document.selection.empty();     } else if(window.getSelection) {         var sel = window.getSelection();         sel.removeAllRanges();     } }   You can also apply these styles to the span for all non-IE browsers and IE10:
span.no_selection {     user-select: none; /* standard syntax */     -webkit-user-select: none; /* webkit (safari, chrome) browsers */     -moz-user-select: none; /* mozilla browsers */     -khtml-user-select: none; /* webkit (konqueror) browsers */     -ms-user-select: none; /* IE10+ */ } 
                        In plain javascript:
element.addEventListener('mousedown', function(e){ e.preventDefault(); }, false);   Or with jQuery:
jQuery(element).mousedown(function(e){ e.preventDefault(); }); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With