How to bind ‘touchstart’ and ‘click’ events but not respond to both?

Update: Check out the jQuery Pointer Events Polyfill project which allows you to bind to “pointer” events instead of choosing between mouse & touch.


Bind to both, but make a flag so the function only fires once per 100ms or so.

var flag = false;
$thing.bind('touchstart click', function(){
  if (!flag) {
    flag = true;
    setTimeout(function(){ flag = false; }, 100);
    // do something
  }

  return false
});

Leave a Comment