jQuery Mobile pagecreate
Event
Example
Display a message before enhancement completes when the page is initialized:
$(document).on("pagecreate", function(){ alert("pagecreate event triggered!")});
Definition and Usage
The pagecreate
event is triggered after the page has been successfully created but before jQuery Mobile completes the page enhancement.
Note: This event is only triggered once per page - when the page is first loaded. jQuery Mobile caches the page in the DOM (memory), so when you navigate back to the first page from a second page via the browser, this event will not be triggered because the first page has already been initialized.
Note: Prior to version 1.4, we used the pageinit
event (deprecated) for this purpose.
Tip: This event is commonly used when users want to enhance custom components:
$(document).on("pagecreate", "#pagetwo", function(event){
$.(":jqmData(role='my-plugin')").myPlugin();
});
Related Events:
- pagebeforecreate - Triggered after page initialization but before enhancement.
- pageinit - Triggered after the page has been fully initialized and enhanced.
Syntax
Trigger the event for all pages in jQuery Mobile:
Trigger the event for a specified page:
Parameter | Description |
---|---|
function(event) | Required. Specifies the function to run when the pagecreate event is triggered. <br> <br>The function has an optional event object that can include any jQuery event properties (event.target, event.type, etc.). For more information, see the jQuery Event Reference. |
page | Optional. Specifies the page ID for which the pagebeforecreate event is triggered. For internal pages, use #id. For external pages, use externalfile.html. |
More Examples
pagebeforecreate and pagecreate Event Example