I'm curious which event is fired first when using jQuery and jQuery Mobile.
Oddly enough, the first console output I get is pagebeforecreate
then document ready
and then onload
.
I would like to know if any other events are being fired before these ones.
/
$('html').bind('pagebeforecreate',function(event) {
console.log("pagebeforecreate");
});
$(document).ready(function() {
console.log("document ready");
});
window.onload = function(){
console.log("onload");
};
I'm curious which event is fired first when using jQuery and jQuery Mobile.
Oddly enough, the first console output I get is pagebeforecreate
then document ready
and then onload
.
I would like to know if any other events are being fired before these ones.
http://jsfiddle/yYGYe/2/
$('html').bind('pagebeforecreate',function(event) {
console.log("pagebeforecreate");
});
$(document).ready(function() {
console.log("document ready");
});
window.onload = function(){
console.log("onload");
};
Share
Improve this question
edited Mar 31, 2013 at 23:03
Jolix
asked Mar 31, 2013 at 22:57
JolixJolix
1431 silver badge6 bronze badges
4
- 1 May we know what for? – Alexander Commented Mar 31, 2013 at 23:07
- Is this specifically about jQuery Mobile? Because pagebeforecreate is not a standard event. – bfavaretto Commented Mar 31, 2013 at 23:10
- 1 Might want to check out stackoverflow./questions/4523954/… – Bart Sipes Commented Mar 31, 2013 at 23:10
- Why not do your things immediately without binding to an event? – John Dvorak Commented Mar 31, 2013 at 23:10
2 Answers
Reset to default 9What you're looking for is a prehensive visualisation of the jQuery mobile event model lifecycle, this diagram below is available in Pro jQuery Mobile and on the author's blog:
Please remember that this is jQuery mobile specific. The list of native events is available as part of the W3 spec, and the only one relevant to the document lifecycle is good old load
.
Your question and the actual thing you are asking are a bit different.
You ask what the first event fired is, but in the context you are asking if pagebeforecreate
is the function to call if you want it to be the first event fired on the page.
If you read the jQuery Mobile documentation on that matter, it says that pagebeforecreate
is called before any "widgets" are instantiated. So in that matter; everything you put in there will be called "before" all jQuery Mobile widgets, but is not per se the first event fired on the HTML page.
The first event fired on an HTML page is probably document.readyState
being set as uninitialized
, indicating your page is not ready loading yet. These are all ready-states;
- uninitialized (Has not started loading yet)
- loading (Is loading)
- interactive (Has loaded enough and the user can interact with it)
- plete (Fully loaded)