How can I make jquery mobile "pagebeforeshow" a fire event every time, not just when updating

I have a jquery mobile page that uses the following code to hide the button when accessing the page.

$('div:jqmData(role="page")').live('pagebeforeshow',function(){ $("#apply_btn").hide() }); 

My problem is that the event is triggered only when the page is refreshed, and not when it arrives at the page from another place on the site.

I tried using the "pagehow" event and the "pageinit" event, but it still fires only when the page is refreshed.

+4
source share
4 answers

Take a look at http://jquerymobile.com/demos/1.1.0/docs/api/events.html

This is the syntax:

 $( '#yourPage' ).live( 'pagebeforeshow',function(event){ $("#uniqueButtonId").hide(); }); 

Luck

+7
source

I just remember that the live method was removed from jQuery 1.9. Now you should use the on method:

 $( '#yourPage' ).on( 'pagebeforeshow',function(event){ $("#uniqueButtonId").hide(); }); 
+10
source

Oddly enough, the short version doesn't work for me:

 $( '#yourPage' ).on( 'pagebeforeshow',function(event){ $('#uniqueButtonId').hide(); }); 

but I have to use:

 $(document).on( 'pagebeforeshow' , '#yourPage' ,function(event){ $('#uniqueButtonId').hide(); }); 
+3
source

try it.

 $('div:jqmData(role="page")').live('pagebeforeshow',function(){ $("#apply_btn",context).hide() }); 
+1
source

All Articles