Description
The .load event occurs when a specified element (and sub elements) have been loaded.
This event works with any element with an URL (like image, script, frame, iframe).
Depending on the browser, the load event may not trigger if the image is cached (Firefox and IE).
Note: There is also a jQuery Ajax method called .load
. Which one is called, depends on the parameter.
v1.0
This method has the form:
.load(handler(eventObject))
Parameter | Description |
---|---|
handler(eventObject) | (required) Specifies a function to execute when the event is triggered |
Return Value
This form returns a jQuery object.
v1.4.3
This method has the alternate form:
.load([eventData],handler(eventObject))
Parameter | Description |
---|---|
eventData | (optional) Specifies additional data to pass along to the event handler |
handler(eventObject) | (required) Specifies a function to execute each time the event is triggered |
Return Value
This form returns a jQuery object.
Examples
Run a function when the page is fully loaded including graphics:
$(window).load(function() {
// run code
});
Change the text of a div element when an image is loaded:
$("img").load(function(){
$("div").text("Image loaded");
});