Skip to content

Instantly share code, notes, and snippets.

@Wynout
Created June 24, 2013 07:22
Show Gist options
  • Save Wynout/5848292 to your computer and use it in GitHub Desktop.
Save Wynout/5848292 to your computer and use it in GitHub Desktop.
jQuery Plugin disableSelection
/**
* jQuery Plugin disableSelection
* Disable selection of text content within the set of matched elements.
*
* @return {Object} jQuery
* @chainable
*/
(function ($, window, document, undefined){
$.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