Last Updated: February 25, 2016
·
10.45K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside