Created
September 16, 2011 05:23
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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