Waiting on the DOM to be ready
jQuery fires a custom event named ready when the DOM is loaded and available for
manipulation. Code that manipulates the DOM can run in a handler for this event. This is a
common pattern seen with jQuery usage.
The following sample features three coded examples of this custom event in use.
Sample: sample3.html
Keep in mind that you can attach as many ready() events to the document as you would like.
You are not limited to only one. They are executed in the order they were added.
Executing jQuery code when the browser window is completely
loaded
Typically, we do not want to wait for the window.onload event. That is the point of using a
custom event like ready() that will execute code before the window loads, but after the DOM is
ready to be traversed and manipulated.
17