Last Updated: February 25, 2016
·
9.847K
· g

Check if Touch Device

//Check Mobile Devices
var checkMobile = function(){

    //Check Device
    var isTouch = ('ontouchstart' in document.documentElement);

    //Check Device //All Touch Devices
    if ( isTouch ) {

        $('html').addClass('touch');

    }
    else {

        $('html').addClass('no-touch');

    };

};

//Execute Check
checkMobile();

1 Response
Add your response

We are in the process of redesigning a site of a client of ours and focusing heavily on mobile devices and mobile traffic. We have been making the site responsive and this jQuery snippet of yours has been extremely helpful! Thanks for posting/sharing. Cheers!

over 1 year ago ·