I currently use the following test (taken out of Modernizr) to detect touch support:
function is_touch_device() {
var bool;
if((\'ontouchstart\' in w
There's a CSS media just for that!
You can check whether some device has a mouse by getting the value of the pointer CSS media feature:
if (matchMedia('(pointer:fine)').matches) {
// Device has a mouse
}
Because it's CSS you don't even need to use JavaScript:
@media (pointer: fine) {
/* Rules for devices with mouse here */
}