suish
suish

Reputation: 3343

The way to use jQuery method for the element of current page in jQueryMobile

This is kind of silly and newbie question though, How would you use jQuery for current page of Jquery mobile which is actually just a Div element in the whole html file. I am currently using $("#" + $.mobile.activePage.attr("id")) to select the current page though,is there any better way to do the same?

InAddition I'd be glad if you suggest the way to select its footer/header elements directly.

Thanks for your answer.

Upvotes: 0

Views: 82

Answers (2)

Omar
Omar

Reputation: 31732

  1. jQuery Mobile <= 1.3

    Use $.mobile.activePage which returns a DOM collection.

    var activePage   = $.mobile.activePage,
        activePageID = activePage[0].id,
        header       = $(".ui-header", activePage), /* or [data-role=header] */ 
        footer       = $(".ui-footer", activePage); /* or [data-role=footer] */
    
  2. jQuery Mobile >= 1.4

    Use $.mobile.pageContainer.pagecontainer("getActivePage").

    var activePage   = $.mobile.pageContainer.pagecontainer("getActivePage"),
        activePageID = activePage[0].id,
        header       = $(".ui-header", activePage), /* or [data-role=header] */ 
        footer       = $(".ui-footer", activePage); /* or [data-role=footer] */
    

Upvotes: 1

Gowrishankar_Ind
Gowrishankar_Ind

Reputation: 61

$('.ui-page-active').attr('id') will do the same for selecting current page in jqueymobile

Upvotes: 0

Related Questions