jQuery Disable Text Select Plugin
Introduction
¶
While making html elements dragable and using them as clickable areas I noticed some little annoyances, mainly the area being selected. This occurs if the user happends to double click, or if the user clicks some element to expand an item then quickly clicking it again to collapse it. The text would become selected. I personally found this very annoying.
So I’ve written a pretty basic jQuery plugin to help with the problem.
Requirements
¶
- jQuery - Core that the plugin runs with
Compatibility
¶
So far the plugin has been tested in windows using the following browsers.
- IE 6, 7
- FF 1.5, 2, 3
- Opera 9
- Safari 3
Usage
¶
HTML
1 2 | <p class="disableSelection">
this text can't be selected. |
Javascript
1 2 3 | $(function() { $('.disableSelection').disableTextSelect(); }); |
Downloads
¶
jquery-disable.text.select.example.htm
jquery.disable.text.select.js (1.16 KB)
jquery.disable.text.select.pack.js (1.07 KB)
Comments
8 Responses to “jQuery Disable Text Select Plugin”
Its works on when you try to select through mouse. This wont work when you do CTRL+A or Right click —>Select ALL.
Thanks
What browser are you using? It could be that the browser just isn’t capable to block selects in that fashion.
Hello,
To disable text selection, your plugin works great !Thanks a lot.
But I also need a function to enable text selection after it has been disabled by your plugin. It will be useful to add a undisableTextSelect function. Do you agree ?
Alex
good point there Alex, I’ve released an updated plugin.
Hi i have a question.
What if i desable the body tag for selection but i whant on div in that body tag where you can select the text.
Is that posible.
In safari my mousedown event got blocked when I would disable my document.onmousedown event. Changing
$(this).bind(’selectstart’, function() {
return false;
});
with:
this.onmousedown = function(){return false};
fixed it. It might be something you would want to look into.
What I meant to say is: ‘In safari the document.mousedown event would be disabled when I disable (any?) elements with the plugin.’
Hi,
This works great in all browser as noted, but it does not work on my Nintendo Wii Opera browser
Great piece of code though, very easy to install, test and use