Skip to content

Instantly share code, notes, and snippets.

@wilhelm-murdoch
Created September 16, 2011 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilhelm-murdoch/1221266 to your computer and use it in GitHub Desktop.
Save wilhelm-murdoch/1221266 to your computer and use it in GitHub Desktop.
Prevents the "bubbling" effect for text selections in the DOM. For example, when you double-click a block of text on a web page and the entire block gets highlighted and selected. Yeah, this prevents that.
(function($){
$.fn.disableSelection = function() {
return this.each(function() {
$(this).attr('unselectable', 'on')
.css({
'-moz-user-select':'none',
'-webkit-user-select':'none',
'user-select':'none'
})
.each(function() {
this.onselectstart = function() {
return false;
};
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment