The ready event method occurs when all the document components have finished loading. It has the following form:
// Is the DOM ready to be used? Set to true once it occurs.
isReady: false,
// Handle when the DOM is ready
ready: function() {
// Make sure that the DOM is not already loaded
if ( !jQuery.isReady ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( jQuery.ready, 13 );
}
// Remember that the DOM is ready
jQuery.isReady = true;
// If there are functions bound, to execute
if ( readyList ) {
// Execute all of them
var fn, i = 0;
while ( (fn = readyList[ i++ ]) ) {
fn.call( document, jQuery );
}
// Reset the list of functions
readyList = null;
}
// Trigger any bound ready events
if ( jQuery.fn.triggerHandler ) {
jQuery( document ).triggerHandler( "ready" );
}
}
},
- jQuery sets a property to check if the DOM is ready to be used (
isReady) containing a boolean value (it defaults tofalse) - checks if the DOM is not already loaded
- checks if a reference to the
bodyelement exists and sets a little time delay to make sure that IE gets it right - sets the
isReadyproperty to true - if there is a list of functions to be executed, it executes all of them by using the
call()function - clears the list of functions by setting its value to
nullto free memory - triggers the
readyevent