3

I have a simple click event attached to a number of anchors on my web app.

$('a.heading').live("click", function(e) {
   e.preventDefault();
   //do my stuff
});

It's not rocket science. However on my iPhone the click doesn't register. It would appear it uses the touch handler for iPhone (iPad, Android etc are all fine).

I've seen a couple of tutorials but cannot seem to get my head around it. Is there not a one liner that I can use that jQuery is so usually good at?

Nakilon
  • 34,866
  • 14
  • 107
  • 142
lunchboxbill
  • 191
  • 3
  • 15
  • iPhone uses touch not click :( http://stackoverflow.com/questions/3705937/document-click-not-working-correctly-on-iphone-jquery – benhowdle89 Jul 26 '11 at 10:48
  • Similar Question : http://stackoverflow.com/questions/671498/jquery-live-removing-iphone-touch-event-attributes – xkeshav Jul 26 '11 at 10:50

1 Answers1

5

This did the trick:

var userAgent = navigator.userAgent.toLowerCase();
var isiPhone = (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipod') != -1) ? true : false;
clickEvent = isiPhone ? 'tap' : 'click';
lunchboxbill
  • 191
  • 3
  • 15