Difference Between jQuery Document.Ready() & Window.Load() Events

Difference Between jQuery Document.Ready() & Window.Load() Events
Rating: 3.5 - 2 Votes

Difference Between jQuery Document.Ready() & Window.Load() Events

jqueryDocument.Ready() event gets fired when DOM is completely loaded, but not its other contents like images, css, iframes etc.

Window.Load() event gets fired when DOM is completely loaded as well as its other contents like images, css, iframes etc.

Document.Ready() event gets fired before Window.Load() event.  This means if you want to do any kind of manipulation with HTML elements like adding click event to a button, you can make use of Document.Ready() event.  If you want to grab some details like image height and width which will take time to load depending upon where it is actually located, you can make use of Window.Load() event.

A sample code is given below, which will display a message box when Document.Ready() and Window.Load() events will be fired.

Before looking over sample code, you must know that $ signs represents jQuery keyword.  You can use either $ or jQuery keyword, both are good to go but by convention, we use $ sign because it will save a lot of time while writing a code and its easy to remember.