Click event not fired on Android 2.3.x
Handle 'click' events in jQuery with support for the default browser shipped with Android Gingerbread (2.3.x)
Posted December 11th, 2012 in javascript
This is something I discovered some time ago, but keeps popping out. Looks like the default browser shipped with Android Gingerbread (2.3.x) doesn't fire neither the click
nor the tap
event. Instead of them, it will fire the touchstart
one.
The solution is handling the correct event based on the browser capability. An example solution is the following:
var touch = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch; var touchEvent = touch ? 'touchstart' : 'click'; $('#anItem').bind(touchEvent, function() { console.log("Touchclicked:", this); });
I made a Gist of it, so if you have a better way to handle it please fork and let me know!
Plus I had an excuse to use the new GitHub Gist interface, it's super cool!