JavaScript touchend versus click dilemma JavaScript touchend versus click dilemma ios ios

JavaScript touchend versus click dilemma


After a day of research, I figured the best solution is to just stick to click and use https://github.com/ftlabs/fastclick to remove the touch delay. I am not 100% sure this is as efficient as touchend, but not far from at least.

I did figure out a way to disable triggering events twice on touch by using stopPropagation and preventDefault, but this is dodgy as it could interfere with other touch gestures depending on the element where it is applied:

button.on('touchend click', function(event) {  event.stopPropagation();  event.preventDefault();  // this fires once on all devices});

I was in fact looking for a solution to combine touchstart on some UI elements, but I can't see how that can be combined with click other than the solution above.


This question is answered but maybe needs to be updated.

According to a notice from Google, there will be no 300-350ms delay any more if we include the line below in the <head> element.

<meta name="viewport" content="width=device-width">

That's it! And there will be no difference between click and touch event anymore!


Yes disabling double-tap zoom (and hence the click delay) is usually the best option. And we finally have good advice for doing this that will soon work on all browsers.

If, for some reason, you don't want to do that. You can also use UIEvent.sourceCapabilities.firesTouchEvents to explicitly ignore the redundant click. The polyfill for this does something similar to your debouncing code.