This is probably the most important function included in the event module, as it can greatly improve the response times of your web applications.
In a nutshell, this is a solid replacement for using window.onload, and attaching a function to that. By using this method, your bound function will be called the instant the DOM is ready to be read and manipulated, which is when what 99.99% of all JavaScript code needs to run.
There is one argument passed to the ready event handler: A reference to the jQuery function. You can name that argument whatever you like, and can therefore stick with the $ alias without risk of naming collisions.
Please ensure you have no code in your <body> onload event handler, otherwise $(document).ready() may not fire.
You can have as many $(document).ready events on your page as you like. The functions are then executed in the order they were added.
| fn | Function | |
|---|---|---|
The function to be executed when the DOM is ready.
function callback(jQueryReference) {
this; // document
}
| ||