jQuery pageinit Event
Example
Alert some text when the page has been initialized and enhanced:
$(document).on("pageinit",function(){
alert("pageinit
event fired!")
});
Try it yourself »
Definition and Usage
The pageinit event was deprecated in jQuery version 1.4.0. Use the pagecreate event instead.
The pageinit event is triggered when the page has been initialized and after jQuery Mobile has finished enhancing the page content.
Before version 1.4, this event was used instead of the jQuery DOM ready() method, to place all other jQuery events and functions. This is because it will work whether the page is loaded directly or through the AJAX call of another page. However, as of version 1.4, this has been replaced by the pagecreate event.
Note: This event is only triggered once per "page" - Every time a page is loaded for the first time, jQuery Mobile caches pages in the DOM (memory), so when you navigate back from pagetwo to pageone (for example), this event will not fire, because then, pageone is already initialized.
Related events:
- pagebeforecreate - triggered when the page is about to be initialized, but before enhancement has begun
- pagecreate - triggered when the page is created, but before enhancement is complete
Syntax
To trigger the event for all pages in jQuery Mobile:
$(document).on("pageinit",function(event){...})
Try it
To trigger the event for a specific page:
$(document).on("pageinit","page",function(event){...})
Try it
Parameter | Description |
---|---|
function(event) | Required. Specifies the function to run when the pageinit event occurs The function has an optional event object, which can contain any jQuery event properties (e.g. event.target, event.type, etc.) See jQuery Events Reference for more information. |
page | Optional. Points to the id of the page to specify the pageinit event for. For internal pages, use #id. For external pages, use externalfile.html. |
Try it Yourself - Examples
A demonstration of pagebeforecreate
and pagecreate
A demonstration that shows when pagebeforecreate and pagecreate fire.
The event object
Using the event.type property to return the triggered event type.