Note that there are some explanatory texts on larger screens.

plurals
  1. POMobile Safari, jQuery, and binding to future DOM elements
    primarykey
    data
    text
    <p>I have an HTML5/JavaScript app built for a car in-dash display unit that I have been asked to port over to run in the browser.</p> <p>Easy task, made some simple changes and now everything works fine in every desktop browser that I tried in.</p> <p>Then, came problems. I was asked to specifically make sure it could run on an iPad for demonstration purposes. </p> <p><strong>THE ISSUE:</strong></p> <p>The app uses single page navigation, using jQuery.load to load in the necessary page fragments as the user navigates to different 'screens.' However, all of the jQuery bindings are centralized in one place so that they are performed on app startup, even though the elements they are binding to may not yet exist in the DOM.</p> <p>That's fine using jQuery.live or .on since they allow binding to future DOM elements. At least in desktop browsers. </p> <p>In Mobile Safari, .live/.on simply do not work for binding to elements that do not yet exist.</p> <p>I have an example to illustrate this problem here: <a href="http://dhines.com/jquery-test/" rel="nofollow">http://dhines.com/jquery-test/</a></p> <p>Notice that all of the 'SHOULD WORK' links do work in desktop browsers, but not Mobile Safari!</p> <p>Looking around the web and SO, the only solution I have found would be to add onclick="function(){}" to all of my clickable elements. This seems dumb.</p> <p>The other option I see would be to decentralize my bindings and have them take place on the specific fragments that they apply to, but given the ton of fragments and bindings, this would not be fun.</p> <p>Looking at my example, can anyone provide me with a better solution? Or perhaps point out whether I'm using .load incorrectly or something? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload