Search code examples
javascriptjqueryhtmlcssdetection

How would I detect touch screens in jquery and hide a div


How would I use this code:

function is_touch_device() {
  return !!('ontouchstart' in window) // works on most browsers 
      || !!('onmsgesturechange' in window); // works on ie10
}; 

to detect touch screens and hide a set of divs with the same class.


Solution

  • You would simply call the function and use basic logic.

    if (is_touch_device()) {
      $('.yourclass').hide();
    }