Reputation: 16641
This should be so easy, but I can't seem to figure it out.
How do I trigger code on a page-load into the DOM (not page-init) in JQuery Mobile?
I'm trying this code, but it doesn't work.
$(document).on("pagecontainerbeforeload", "#my-page-id", function(event, data) {
console.log("page load");
});
Using JQuery Mobile 1.4.4 and JQuery 2.1.1
Here's a Fiddle that shows what I tried: http://jsfiddle.net/wpgs06r1/2/
Upvotes: 0
Views: 158
Reputation: 24738
Instead of $(document) as the selector, the pagecontainer widget is in the body, so try:
$( "body" ).on( "pagecontainerbeforeshow", function( event, ui ) {} );
You can also use the jQM selector, :mobile-pagecontainer instead of body:
$( ":mobile-pagecontainer" )
Upvotes: 1