Skip to content

Instantly share code, notes, and snippets.

@html
Created July 7, 2012 11:36
Show Gist options
  • Save html/3065998 to your computer and use it in GitHub Desktop.
Save html/3065998 to your computer and use it in GitHub Desktop.
Enable/disable selection in jQuery
// Stolen from jquery-ui and customized
(function($){
$.fn.disableSelection = function(){
return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
".disableSelection", function( event ) {
event.preventDefault();
});
};
$.fn.enableSelection = function(){
return this.unbind('.disableSelection');
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment