In the below parsing phase,
When does $document.ready() get executed?
When does $document.ready() get executed?
.ready() can be executed multiple times
.ready( handler )
Returns:jQuery
Description: Specify a function to execute when theDOMis fully loaded.If
.ready()is called after theDOMhas been initialized, the new handler passed in will be executed immediately.The
.ready()method can only be called on a jQuery object matching the current document, so the selector can be omitted.
n = -1;
function ready() {
document.getElementsByTagName("p")[0].textContent += "ready " + ++n + "\n";
}
$(document).ready(ready);
$(document).ready(function() {
ready();
$(document).ready([function() {
ready()
},
function() {
$(document).ready(function() {
ready();
$(document).ready([
function() {
ready()
}, function() {
ready()
if (n === 5) $(document).ready(function() {ready()})
}]);
})
}
])
})
See soruce at ready.js
if ( document.readyState === "complete" ||
( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
window.setTimeout( jQuery.ready );
} else {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", completed );
// A fallback to window.onload, that will always work
window.addEventListener( "load", completed );
}