"$ (document) .on ('pageshow'" does not work with jQuery 1.9.1 + JQM 1.3.0-stable

Work with jQuery 1.8.3

<!DOCTYPE html> <html> <head> <script src="js/jquery-1.8.3.min.js"></script> <script src="js/jquery.mobile-1.3.0.min.js"></script> <script> $.support.cors = true; $.mobile.allowCrossDomainPages = true; $("#home").live("pageshow", function( event ) { alert( "Ok. This is Home!" ); }); </script> </head> <body> <!--- HOME ---> <div data-role="page" id="home"> <h2>Hello World</h2> </div> </body> </html> 

Alert is working fine.

However, with jQuery 1.9.1 (note that I changed the version and live with on.

 <!DOCTYPE html> <html> <head> <script src="js/jquery-1.9.1.min.js"></script> <script src="js/jquery.mobile-1.3.0.min.js"></script> <script> $.support.cors = true; $.mobile.allowCrossDomainPages = true; $("#home").on("pageshow", function( event ) { alert( "Ok. This is Home!" ); }); </script> </head> <body> <!--- HOME ---> <div data-role="page" id="home"> <h2>Hello World</h2> </div> </body> </html> 

Warning does not work. I am sure that I am doing something wrong. I read that jQuery Mobile 1.3.0-stable will use jQuery 1.9.1, but maybe I'm wrong.

+6
source share
1 answer

Edit

  $("#home").on("pageshow", function( event ) { 

to

  $(document).on("pageshow", "#home", function( event ) { 

The on syntax does not match the syntax of live : the element that will receive and delegate the event must exist when creating the binding.

+12
source

All Articles