0

Im trying to reproduce the common issue with jquery click not working on ipad. And it works for me all the time. Heres the jsfiddle: http://jsfiddle.net/EbE2M/11/ As so ask to provide some code, here it is from the fiddle above:

$('.test').on('click', function(e){
   //some stuff to test here
});

Am I missing anything or does it work for some ipads only and doesnt work for other? What version of safari and ipad I need to reproduce the issue?

UPDATE: To find examples of click not working on iPad, just google for "iPad click event not working". Here are two examples from so. Why I ask this if things are working for me? Because things may not work for my clients and "works on my machine" is not reliable. I would like to get something like versions of iPad or safari on which click doesnt work properly. With jsfiddle example preferably. So that I could get this iPad from friend/shop and check it. If its the one can reproduce this kind of issues I just buy it and use it for testing during development.

Community
  • 1
  • 1
Yaroslav Yakovlev
  • 6,303
  • 6
  • 39
  • 59
  • "And it works for me all the time" - if it is working, then what is the issue..? – T J Jul 15 '14 at 07:02
  • Because it doesnt work for some other people. Google for "ipad click event not working". And "works on my machine" is not good enough for me. – Yaroslav Yakovlev Jul 15 '14 at 07:12
  • Would like downvoters to explain their downvotes, ofcourse :-). It seems like most people read:"works for me" and without reading to the end ask: whats your problem if it works? Please read the whole question and explain the downvotes. – Yaroslav Yakovlev Jul 15 '14 at 07:22
  • If it works for you all the time, then it's obvious that it's the problem with the other people code, not the iPad. If you have seen people complaining something is not working in iPad were they simply saying it doesn't work in none of the iPad..? if so, it is obvious that issue is with their code, because usually it works in iPad as you experienced. if not, they probably mentioned the version of iPad already. "What version of safari and ipad I need to reproduce the issue?" - what issue..? before the edit your question was unclear. how do we know what was the cause of issue you saw in google? – T J Jul 15 '14 at 07:36
  • Not everyone will encounter such issues, it highly depends upon the code, structure of `dom`, how they're binding events etc. Even if somebody experience a particular issue in one version of iPad, other guys issue will be something else with another version of iPad, it's all highly dependent on the scenario. How do you expect someone to answer: "ohkey, whatever you do this version will produce issue, this and this will not" ? somebody else will obviously come up saying "hey dude, but i had issue in that version!". you might want to refer to apple forum or something. My humble opinion. – T J Jul 15 '14 at 07:48
  • Tilwin Joy. In ideal world I would get a table of devices that do not support click or cases when devices dont support click. Issue was not in the code, issue was that the same code didnt work for some people as can be seen from questions on so I`ve added in update. I think its important to know when clic doesnt work and having a table of cases would be great for anyone who have this issue. – Yaroslav Yakovlev Jul 15 '14 at 09:03
  • As far as i know, all browsers supports `click`, touch device browsers simulates a click (*triggers a click after 300ms*) for backwards compatibility. So if your code is straight forward there won't be any issue so it's unlikely that such a table exists. Like i said before, If there are issues, it must be related to the particular scenario, for e.g. if a browser might be rendering an element in front of the clickable, then your `click` obviously won't work - but it isn't a problem with browser not supporting *click*, it's an issue highly dependent on the scenario- css, event bindings etc. – T J Jul 15 '14 at 09:10
  • Tilwin Joy, did you go through 2 links I`ve added to question update? It seems examples there are quite straightforward. Are you sure all he browsers can handle click all the time? Why are there lots of topics all over the net, that iPads have click issues? – Yaroslav Yakovlev Jul 15 '14 at 09:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57316/discussion-between-yaroslav-yakovlev-and-tilwin-joy). – Yaroslav Yakovlev Jul 15 '14 at 09:18

2 Answers2

2

Any non-anchor element assigned a click handler in jQuery must either have an onClick attribute (can be empty like below):

onClick=""

OR

The element css needs to have the following declaration:

cursor:pointer

DEMO, Details

Manwal
  • 23,450
  • 12
  • 63
  • 93
  • I saw this one too. But the problem is that it worked on both iPad and Android for me. Even without these workarounds. So the question remains, what device need this fixes to make it work? – Yaroslav Yakovlev Jul 22 '14 at 06:33
1

The click ( as any other ) event has to be bound directly to the element for iOS-s for correct registration. This means that delegated event handlers will not work on some iOS devices.

In my opinion, that's what You're looking for.

You can not ensure, that

$(document).on("click", "someSelector", function(e) { doSomething(); });

will work properly, but You can, using (for example) Your snippet:

$('.test').on('click', function(e){ doSomething(); });

since this way, it is directly registered on the element itself.

István Pálinkás
  • 2,217
  • 7
  • 25
  • 50
  • Here are couple of questions where click on the selector, not document, doesnt work on ipad: http://stackoverflow.com/questions/7892863 http://stackoverflow.com/questions/17161514 Will update the question, it seems its not clear. – Yaroslav Yakovlev Jul 15 '14 at 07:16