lunchboxbill
lunchboxbill

Reputation: 191

iPhone jQuery click event

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?

Upvotes: 3

Views: 7310

Answers (1)

lunchboxbill
lunchboxbill

Reputation: 191

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';

Upvotes: 5

Related Questions