Last active
October 11, 2015 03:17
-
-
Save barneycarroll/3794102 to your computer and use it in GitHub Desktop.
Turn selectability on or off via jQuery
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
// Selectability: pass true or false | |
// http://stackoverflow.com/questions/2700000/how-to-disable-text-selection-using-jquery | |
$.fn.selectable = (function _selectable(){ | |
var values = [ | |
// Off | |
['on', 'none', false], | |
// On | |
['off','text', $.noop] | |
]; | |
return function select(boolean){ | |
var value = values[~~boolean]; | |
return this | |
.attr('unselectable', value[0]) | |
.css( 'user-select', value[1]) | |
.on( 'selectstart', value[2]); | |
}; | |
}; | |
()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment