I have a project using jQuery and a lot of dynamically generated content. There is a click handler on the upper left element - the “initiative” rating - and it works fine on the Safari desktop, but not called on Mobile Safari at all; a gray overlay never appears and no action is taken. This is the same story with a click handler on the Hit Points area (172 on the right) and status ("Add status effect" at the bottom, confirm, appears above the portrait): everything works on the desktop, but not on mobile Safari.
I reduced the code to the following:
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script> $(function() { $('#dynamic').click(function() {alert("works")}); $('#dynamic-with-onclick').click(function() {alert("works")}); $('#dynamic-with-dynamic-onclick').click(function() {alert("works")}).attr('onclick', ''); }) </script> </head> <body> <ul> <li id='static' onclick='alert("works")'>If there an onclick it called</li> <li id='dynamic'>And if there no onclick the iPad won't see other click events</li> <li id='dynamic-with-onclick' onclick=''>But if there is one all events are called</li> <li id='dynamic-with-dynamic-onclick'>And if we add one everything works</li> </ul> </body> </html>
Update
It seems a lot easier than when I initially asked this question 10 months ago; Using modern Mobile Safari, all click handlers will be registered as usual. So go ahead and just use $(...).click(function() {}) !
Tallama
source share