jQuery Mobile Events
Event = The response actions for all different visitors accessing the page.
jQuery Mobile Events
In jQuery Mobile, you can use any standard jQuery events.
Additionally, jQuery Mobile provides events specifically for mobile browsers:
- Touch events - Triggered when the user touches the screen.
- Swipe events - Triggered when the user swipes up or down.
- Orientation events - Triggered when the device is rotated horizontally or vertically.
- Page events - Triggered when a page is shown, hidden, created, loaded, or unloaded.
Initializing jQuery Mobile Events
When learning jQuery, we learned to use $(document).ready()
to ensure your jQuery code scripts start executing after the DOM elements have loaded:
jQuery document ready event
However, in jQuery Mobile, use the pageinit
event to set your code scripts to start executing after the DOM elements have loaded. This is necessary to execute scripts when any new page is loaded and created, so you need to bind the pageinit
event.
The second parameter ("#pageone") specifies the page ID for the event:
jQuery Mobile pagecreate event
| | Note: The jQuery on()
method is used to bind events to selected elements. |
| --- | --- |
In the next section, we will discuss jQuery Mobile events in more detail.