Ok so I have started using jQuery Mobiles pre-fetch abilities. I’m using the link method specified on this page http://jquerymobile.com/test/docs/pages/page-cache.html. The only problem is my swipe code fails to see the pages that were brought in via the pre-fetch. Please see this js fiddle for a working example of the problem.
Any one have any thoughts as to what to try to get .next to find the new pages. I have also tried targeting them via
div.ui-page
And it still comes up as an empty selector in firebug.
The issue is that you are attempting to select the next DOM element, not the next pesueo-page element. Since you are adding the last page after the DOM loads, it’s actually being added after another element (so
.next()is selecting this other element instead of the pseudo-page).I changed:
To:
Which selects all the previous/next pseudo-pages and then selects just the first of those.
Here is a demo: http://jsfiddle.net/UurQC/2/
If you don’t delegate the event handlers for the swipe events then the swipe event handlers won’t run for the dynamically placed pseudo-page. Here’s how to fix that:
And here is a demo: http://jsfiddle.net/UurQC/3/
UPDATE
Here is what the DOM looks like and why the above is necessary:
Note that this is not the full HTML but only the direct children of the
<body>element.Notice that the dynamically created pseudo-page is added to the DOM after JSFiddle added your JS code in a
<script>tag. This will be an issue when not run on JSFiddle as well, as jQuery Mobile adds a loader element as it initializes.