Smith
Smith

Reputation: 5961

detect pageshow(n) for multiple pages

i have created a handler to trap pageshow for multiple ages like so

$(document).on('pageshow',"#novels, #book, #toys",function(event){

}

each page has an id like so

<div data-role="page" data-theme="c" id="pagename"></div>

how do i get the pages that call the pageshow events, i tried

console.log($(this).attr('id'));

in the pageshow evens, but got undefined in the console

Upvotes: 0

Views: 97

Answers (1)

Omar
Omar

Reputation: 31732

jQuery Mobile <= 1.3

$(document).on("pageshow", function () {
  var activePage = $.mobile.activePage[0].id;
  console.log( activePage ); // pageID of active page
});

jQuery Mobile >= 1.4

$(document).on("pagecontainershow", function () {
  var activePage = $.mobile.pageContainer.pagecontainer("getActivePage")[0].id;
  console.log( activePage ); // pageID of active page
});

Upvotes: 2

Related Questions