jQuery Mobile -> Page Lifecycle?

Nik picture Nik · Mar 5, 2013 · Viewed 7.5k times · Source

Is there something like a lifecycle for jQuery Mobile pages? Like events that get fired on init, show, hide/back, or whatever events?!

Thanks in advance!

Answer

Gajotres picture Gajotres · Mar 5, 2013

Intro

All information found here can also be found in my blog ARTICLE, you will also find working examples.

During the page transition:

event pagebeforecreate

event pagecreate

Best event if you want to dynamically add page content and let jQuery Mobile style yout new content. Don't use it in case of ajax call, pagebefore show should be used then but all dynamically added content them must be manually enhanced.

event pageinit

It will only trigger once per page load, any return to the page will not trigger it again, unless page is manually refreshed

event pagebeforehide

event pagebeforeshow

Best event for the page manipulation

event pageremove

event pagehide

event pageshow

Only event where other graphic jQuery/javascript can be initialized and used, like graph tools or carousels

Rest of them:

event pagebeforechange

Will always trigger twice so skip it

event pagechange

Will always trigger twice so skip it

If you want to find more about this topic and how page events work overall take a look at my other ARTICLE. Or find it HERE. Just search for the chapter called Page events transition order. But also read everything anywhere.

Official documentation: http://jquerymobile.com/demos/1.2.0/docs/api/events.html