You can do the trick using CSS : http://jsbin.com/uxewej/8/
html{
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
Do not use html
CSS selector if you need to let the user select something.
Update
Tested with FF, Chrome and IE9
Generic solution in complement of CSS declarations
function toggleEnableSelectStart(enable) {
document.onmousedown = function (e) { return enable; };
document.onselectstart = function (e) { return enable; };
}
jQuery(document).ready(function () {
//Disable default text selection behavior
toggleEnableSelectStart(false);
//Let inputs text selection possible
jQuery("input[type=text]").focusin(function () { toggleEnableSelectStart(true); });
jQuery("input[type=text]").mouseover(function () { toggleEnableSelectStart(true); });
jQuery("input[type=text]").focusout(function () { toggleEnableSelectStart(false); });
jQuery("input[type=text]").mouseout(function () { toggleEnableSelectStart(false); });
});
Sorry about the author, I don't remember where I found that one day, but it is clever!
Update 2
To avoid the clicking selection behavior only on your button, remove the CSS tricks and use
http://jsbin.com/uxewej/11/edit
function toggleEnableSelectStart(enable) {
document.onmousedown = function (e) { return enable; };
document.onselectstart = function (e) { return enable; };
}
jQuery(document).ready(function () {
//Disable default text selection behavior
toggleEnableSelectStart(false);
//Let inputs text selection possible
jQuery(".countButton").focusin(function () { toggleEnableSelectStart(false); });
jQuery(".countButton").mouseover(function () { toggleEnableSelectStart(false); });
jQuery(".countButton").focusout(function () { toggleEnableSelectStart(true); });
jQuery(".countButton").mouseout(function () { toggleEnableSelectStart(true); });
});
Update 3
If you want to disable selection on selected element follow this link
(function($){
$.fn.disableSelection = function() {
return this
.attr('unselectable', 'on')
.css('user-select', 'none')
.on('selectstart', false);
};
})(jQuery);