Skip to content

Instantly share code, notes, and snippets.

@ten1seven
Created November 15, 2011 23:26
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ten1seven/1368732 to your computer and use it in GitHub Desktop.
Save ten1seven/1368732 to your computer and use it in GitHub Desktop.
Enable/Disable text selection
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');
});
};
@ten1seven
Copy link
Author

jQuery plugin that disables/enables text select on elements. Useful to prevent pesky text selection during drag interaction.

Requirement: jQuery
Usage: $('body').disableTextSelect();

@html
Copy link

html commented Jul 7, 2012

here is my alternative, I've created and after that found yours
https://gist.github.com/3065998

@notajingoist
Copy link

Hehe, thanks Jeremy! :)

@scottcioffi
Copy link

its GREAT, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment