Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I make jquery mobile "pagebeforeshow" event fire every time, not just on refresh

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

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

My problem is that the event only fires when the page is refreshed and not when arriving at the page from somewhere else in the site.

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

like image 410
Finglish Avatar asked Nov 29 '22 16:11

Finglish


2 Answers

Just to remember that live method has been removed from jQuery 1.9. You should use from now on the on method:

$( '#yourPage' ).on( 'pagebeforeshow',function(event){
    $("#uniqueButtonId").hide();
});
like image 139
jalogar Avatar answered Dec 04 '22 23:12

jalogar


Have 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();
});

Good Luck

like image 38
TheGwa Avatar answered Dec 05 '22 01:12

TheGwa