Today I was testing an application that used a click event to utilise a few different jQuery functions, for example hiding an element. The application works great and the jQuery adds very nice interactions for the user experience.
Whilst testing for the iPad however I found that the ‘click’ event was ignored by the iPad, which would make sense seeing as you can’t “click” the touchscreen. So what to do?
It turns out that there is a solution to this by sniffing the userAgent, a bit rubbish I know seeing as we are taught that browser sniffing should only be considered in desperate times, as a desperate measure.
My solution was a simple one, changing this…
$('body').on 'click', 'a.close', close_box
to this…
$('body').on 'click touchstart', 'a.close', close_box
By adding the ‘touchstart’ event, which is the iPad equivalent to ‘click’, jQuery reads it as “either click OR touchstart”.