How do I use jQuery for click event in iPhone web application How do I use jQuery for click event in iPhone web application jquery jquery

How do I use jQuery for click event in iPhone web application


I struggled with this as well. After lots of toying around and trying to figure out the problem, I came across a simple solution.

If you set the element's cursor to pointer, it magically works again with Jquery's live and the click event. This can just be set globally in the CSS.


You need to listen for the "touchstart" and "touchend" events. Add the listeners with jQuery...

$('span').bind( "touchstart", function(e){alert('Span Clicked!')} );

You may wish to listen for a touchstart and touchend so that you can verify that the element targeted when the finger touched is the same as the element targeted when the finger was removed.

I'm sure there is probably a better way to do it but that should work :)

Edit: There is a better way! See https://stackoverflow.com/a/4910962/16940


You actually don't need to use the touchstart or touchend event, so long as the 'span' tag (or anything other than an 'a' tag) has a css property of:

cursor:pointer

the click will register