Skip to content

Instantly share code, notes, and snippets.

@somebox
Created September 20, 2011 11:42
Show Gist options
  • Save somebox/1228913 to your computer and use it in GitHub Desktop.
Save somebox/1228913 to your computer and use it in GitHub Desktop.
jQuery snippet to make page elements unselectable (disable highlights)
/* disable user selections */
jQuery.fn.disableSelection = function(){
$(this).each(function(){
$(this).attr('unselectable', 'on')
.css('-moz-user-select', 'none')
.each(function() {
this.onselectstart = function() { return false; };
});
});
};
@somebox
Copy link
Author

somebox commented Sep 26, 2011

Note that this function is part of jQueryUI (used for Sortable), but it is still "undocumented" as far as I can tell.

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