jQuery Load | How to use load method of jQuery on window, image examples

jQuery load() method

The load() method, which is deprecated in 1.8 version of jQuery library, is used to perform actions as load event occurs. The load event happens when a specified element like images, iframes, frames scripts or window is completely loaded.

The load() method becomes challenging, especially in case of images loading as it comes to compatibility of browsers, when execution of functions are also attached to load() method. For example if images are already in cache it may cease to execute.

Syntax of load() method





Running example of load() method with an image

In example below the load event of image will trigger an alert showing image is loaded.

Experience this example online

 Example of using  jQuery window load()

This example will display an alert when whole document is loaded, including all images and other content.

Experience this example online

There is another method with same name load() which is associated with loading data from server and placing the returned HTML into matched elements. This comes under AJAX method.

Was this article helpful?

Related Articles

Leave A Comment?