Direto do Modernizer.
var is_touch_device = function() {
var bool;
if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
bool = true;
}
return bool;
};
if(is_touch_device()) {
$("html").addClass("touch");
}