February 27, 2013

jquery click event in iOS

When binding a click event to the element, iOS may not work as expected. It is because if you write something like below, it won't work. Maybe it is iOS bug/jQuery bug?

$('#button1').click(function() {
    alert('button1');
});
The work around fix is to set pointer cursor to the element, and use .on to bind click event.

$('#button1').css('cursor','pointer');
$(document).on('click', '#button1',  function(event) {
    event.preventDefault()
    alert('button1');
});

2 comments:

  1. Hello Friends! Call us today so we can help you optimize your company's position on the top 5 search engines! Links, tags, and labels make a huge difference- let's talk about how and why! Call us soon! Have a great weekend, be safe! CodCow

    ReplyDelete
  2. New web site is looking good. Thanks for the great effort. cell phone deals

    ReplyDelete