Last Updated: February 25, 2016
·
1.04K
· kevincennis

Faster clicks on touch devices

On touch devices, click events can take a while to fire - and for users, that often makes your web app feel slow.

Here's a really easy way to mitigate that problem:

var click = !!('ontouchstart' in window) ? 'touchstart' : 'click';

$('#someElement').on(click, function(){...});

Or...

document.addEventListener(click, function(){...}, false);

So, we bind to touchstart for touch devices to make the interactions faster, and fallback to click for non-touch devices.

2 Responses
Add your response

This is beautifully elegant. Well done!

over 1 year ago ·

awesome. just watch out for using it inside scrollable areas :)

over 1 year ago ·