ドキュメント

Events/load

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Events

load( fn )

Binds a function to the load event of each matched element.
When bound to the window element, the event fires when the user agent finishes loading all content within a document, including window, frames, objects and images. For elements, it fires when the target element and all of its content has finished loading. Note: load will work only if you set it before the element has completely loaded, if you set it after that nothing will happen. This doesn't happen in $(document).ready(), which jQuery handles it to work as expected, also when setting it after the DOM has loaded.
Arguments:
fnFunction
A function to bind to the load event on each of the matched elements.
function callback(eventObject) {
  this; // dom element
}
Examples:

Run a function when the page is fully loaded including graphics.

$(window).load(function () {
  // run code
});

Add the class bigImg to all images with size greater then 100 upon each image load.

$('img.userIcon').load(function(){
  if($(this).height() > 100) {
    $(this).addClass('bigImg');
  }
});

NameType