jQuery pagebeforecreate Event

## jQ Mobile Tutorial

jQ Mobile HOME jQ Mobile Intro jQ Mobile Install jQ Mobile Pages jQ Mobile Transitions jQ Mobile Buttons jQ Mobile Icons jQ Mobile Toolbars jQ Mobile Navbars jQ Mobile Collapsibles jQ Mobile Grids

## jQ Mobile Lists

jQ Mobile List Views jQ Mobile List Content

## jQ Mobile Forms

jQ Mobile Form Basic jQ Mobile Form Inputs jQ Mobile Form Select jQ Mobile Form Sliders

## jQ Mobile Themes

jQ Mobile Themes

## jQ Mobile Events

jQ Mobile Events jQ Mobile Touch jQ Mobile Scroll jQ Mobile Orientation jQ Mobile Page Events

## Examples

jQ Mobile Examples

## References

jQ Data Attributes jQ Events jQ Icons

# jQuery pagebeforecreate Event

jQuery Mobile Events

## Example

Alert some text when the page is being initialized, but before enhancement has begun:

$(document).on("pagebeforecreate",function(){
alert("pagebeforecreate event fired!")
});
Try it yourself »

## Definition and Usage

The pagebeforecreate event is triggered when the page is about to be initialized and before jQuery Mobile has started enhancing the page.

Use this event to manipulate content before jQuery Mobile has had a chance to do so. For example, if you want to add data attributes via a script instead of in the HTML source (see example below).

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:

- pagecreate - triggered when the page is created, but before enhancement is complete
- pageinit - triggered when the page has been initialized and enhancement is complete

## Syntax

To trigger the event for all pages in jQuery Mobile:

$("document").on("pagebeforecreate",function(event){...}) Try it

To trigger the event for a specific page:

$("document").on("pagebeforecreate","page",function(event){...}) Try it

Parameter | Description
--- | ---
function(event) | Required. Specifies the function to run when the pagebeforecreate 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 pagebeforecreate event for. For internal pages, use #id. For external pages, use externalfile.html.

## Try it Yourself - Examples

A demonstration of pagebeforecreate, pagecreate and pageinit
A demonstration that shows when pagebeforecreate, pagecreate and pageinit fire.

Manipulate content before jQuery Mobile has had a chance to do so
Using the pagebeforecreate event to dynamically add an attribute.

The event object
Using the event.type property to return the triggered event type.

jQuery Mobile Events

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE