Try it like this:
var clickOrTap = ( typeof document.body.ontouchend === "undefined" ) ? 'click' : 'touchend'; $( "body" ).on( clickOrTap, function() { ... } );
It checks if the device has a touchend event, and if this does not mean that you are on the desktop, so that the listener will wait for a click . If it is defined, then you are on the touch device and you can listen to touch events.
source share