Created
November 15, 2011 23:26
-
-
Save ten1seven/1368732 to your computer and use it in GitHub Desktop.
Enable/Disable text selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.disableTextSelect = function() { | |
return this.each(function() { | |
$(this).css({ | |
'MozUserSelect':'none', | |
'webkitUserSelect':'none' | |
}).attr('unselectable','on').bind('selectstart', function() { | |
return false; | |
}); | |
}); | |
}; | |
jQuery.fn.enableTextSelect = function() { | |
return this.each(function() { | |
$(this).css({ | |
'MozUserSelect':'', | |
'webkitUserSelect':'' | |
}).attr('unselectable','off').unbind('selectstart'); | |
}); | |
}; |
here is my alternative, I've created and after that found yours
https://gist.github.com/3065998
Hehe, thanks Jeremy! :)
its GREAT, thanks!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jQuery plugin that disables/enables text select on elements. Useful to prevent pesky text selection during drag interaction.
Requirement: jQuery
Usage: $('body').disableTextSelect();