Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable text highlighting on double click in jQuery [duplicate]

I have this jQuery toggle. It work fine.

   <ul>     <li>Go to the store</li>     <li>Pick up dinner</li>     <li>Debug crash</li>     <li>Take a jog</li>   </ul> 

 

        $("li").toggle(           function () {             $(this).css({"list-style-type":"disc", "color":"blue"});           },           function () {             $(this).css({"list-style-type":"disc", "color":"red"});           },           function () {             $(this).css({"list-style-type":"", "color":""});           }         ); 

The problem is when I do fast clicking, it highlighted the text in it. Is there a way to stop the text from being highlighted?

like image 756
Reigel Avatar asked Jan 25 '10 12:01

Reigel


1 Answers

I'm writing on iPhone, while away from the desk, but a quick Google turned up this page: disable text selection with jQuery.


Edited in response to the 'dead link' comment (from @Herb Caudill). While the original link is, indeed, dead, it appears to be due to a site restructuring (rather than removal) and the new location for the article can be found here: http://chris-barr.com/index.php/entry/disable_text_selection_with_jquery/

And the code provided in that article is reproduced below:

$(function(){     $.extend($.fn.disableTextSelect = function() {         return this.each(function(){             if($.browser.mozilla){//Firefox                 $(this).css('MozUserSelect','none');             }else if($.browser.msie){//IE                 $(this).bind('selectstart',function(){return false;});             }else{//Opera, etc.                 $(this).mousedown(function(){return false;});             }         });     });     $('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect' }); 

jQuery snippet written by Chris Barr, of chris-barr.com, as accessed on Friday, 21st of January, 2011.

like image 84
2 revs Avatar answered Sep 30 '22 18:09

2 revs