Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active October 11, 2015 03:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/3794102 to your computer and use it in GitHub Desktop.
Save barneycarroll/3794102 to your computer and use it in GitHub Desktop.
Turn selectability on or off via jQuery
// 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