It took my a while to find a bit of script that worked cross browser, but the jquery plugin at http://code.jdempster.com/jQuery.DisableTextSelect/ does the job!
When working on the UI of a web application text would often get selected by the browser incorrectly, for example while dragging an element, or clicking on an element with an onclick event.
If you are using jquery already; download it, include it, then use:
$(‘.elementsToDisableSelectFor’).disableTextSelect();
If you need this functionality without including the whole of jquery, take a look at the source code for the plugin. It’s only about 20 lines long. It uses a different method for Firefox and Internet Explorer, with a fallback for everything else but it should be easy to convert in to native JS or another javascript framework.
Warning: Declaration of Social_Walker_Comment::start_lvl(&$output, $depth, $args) should be compatible with Walker_Comment::start_lvl(&$output, $depth = 0, $args = Array) in /home/customer/www/arronwoods.com/public_html/blog/wp-content/plugins/social/lib/social/walker/comment.php on line 18
Warning: Declaration of Social_Walker_Comment::end_lvl(&$output, $depth, $args) should be compatible with Walker_Comment::end_lvl(&$output, $depth = 0, $args = Array) in /home/customer/www/arronwoods.com/public_html/blog/wp-content/plugins/social/lib/social/walker/comment.php on line 42
The link to your script is broken.
Sweet. Wonder why more people aren’t using this. Really helps break the line between app and document.
Hi friend,
How to use this jquery to disable text selection. Please tell me.
Thanks a lot!
I just plugged it into my color selector plugin and it works just great. 🙂
[…] […]
Thanks! That’s working well! And this plugin doesn’t prevent observing click event, what was critical for me.
Very neat script, very clever. This would work very well for preventing people stealing your content, but it is obviously not a fool proof solution, but nothing is!
It’s a really great and useful plugin! Thanks
Not working in chrome, input are disabled as well 🙁
Thanks, very useful