JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test" class="unselectable">asd</div>
CSS
*.unselectable {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
#test {
width: 200px;
height: 200px;
background: lightblue;
}
JavaScript
$(document).ready(function() {
$.ctrl = function(key, callback, args) {
var isCtrl = false;
$(document).keydown(function(e) {
if (!args) args = []; // IE barks when args is null
if (e.ctrlKey) isCtrl = true;
if (e.keyCode == key.charCodeAt(65) && isCtrl) {
callback.apply(this, args);
return false;
}
}).keyup(function(e) {
if (e.ctrlKey) isCtrl = false;
});
};
//Other Method
$(function() {
$(document).keydown(function(objEvent) {
if (objEvent.ctrlKey) {
if (objEvent.keyCode == 65) {
objEvent.disableTextSelect();
return false;
}
}
});
});
});