jQuery load()Method

jQuery 事件方法jQuery Event Methods

Examples

Alert text when all images are loaded:

$("img").load(function(){
alert("Image loaded");
});

Try it Yourself »

Definition and Usage

The load() method in jQuery version 1.8 wasDeprecated。

The load() method attaches an event handler to the load event.

The load event occurs when the specified element has been loaded.

This event works for any element with a URL (such as images, scripts, frames, iframes) as well as the window object.

Depending on the browser (Firefox and IE), the load event may not be triggered if the image has been cached.

Note:There is also a jQuery method called load() AJAXMethod. Which method is called depends on the parameters.


Syntax

$(selector).load(function)

Parameter Description
function Required. Specifies the function to run when the specified element finishes loading.


实例

More Examples

Display some text when all images are loaded
How to change the text of a <div> element when all images are loaded.

Alert text when the page is fully loaded
Alert text when the window object (including images) is fully loaded.


jQuery 事件方法jQuery Event Methods

Other Extensions