jQuery load Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Browser Events

Definition

The load event fires on an element when it and all of its sub-resources have finished loading. It applies to elements with a URL — <img>, <script>, <iframe> — and to window. Bind with .on("load", handler) (since 1.7) and fire it for tests with .trigger("load"). This is the browser event, not the Ajax method .load(url).

Syntax

Start with these common calls. Keep them short and readable.

jQuery
// Image: bind BEFORE setting src
$("#book")
  .on("load", function () {
    // image finished loading
  })
  .attr("src", "photo.png");

// Whole page: DOM + images, stylesheets, frames
$(window).on("load", function () {
  // every asset is ready
});

// iframe
$("#frame").on("load", function () { /* frame content loaded */ });

// Fire for tests
$("#book").trigger("load");

// Not this - that is the Ajax method:
// $("#box").load("/partial.html");
CallWhat it does
.on("load", handler)Run handler when the element has loaded
.on("load", eventData, handler)Same, with data available as event.data
.one("load", handler)Run the handler at most once
$(window).on("load", handler)Wait for the full page and every asset
.trigger("load")Fire bound handlers without a real load

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the element: an <img>, <iframe>, <script>, or window.
Step 2Attach .on("load", handler) before setting src.
Step 3Set src (or let the page load). The handler receives an event object; this is the element.

Return Value

Return ValueDescription
jQuery object.on() returns the original collection so you can chain .attr("src", ...) and more.

jQuery Examples

Example 1 — Image: Bind Before Setting src

Attach load first, then set src so a fast or cached load is not missed.

jQuery
$("#book")
  .on("load", function () {
    $("#log").text("Image loaded: " + this.naturalWidth + "x" + this.naturalHeight);
  })
  .attr("src", "photo.png");
Try It Yourself

How It Works

  1. Bind. .on("load") registers the handler on the image.
  2. Load. .attr("src") starts the request.
  3. Fire. When the image is ready the handler reads its natural size.

Example 2 — $(window).on("load") vs Document Ready

Ready fires when the DOM is parsed; window load waits for images, styles and frames too.

jQuery
$(function () {
  $("#log").append("1. DOM ready\n");
});

$(window).on("load", function () {
  $("#log").append("2. window load (all assets)\n");
});
Try It Yourself

How It Works

  1. Ready. $(function(){}) runs once the DOM is built.
  2. Load. $(window).on("load") runs after images, stylesheets and frames finish.
  3. Choose. Use ready for DOM work; use load when you need image sizes or full layout.

Example 3 — iframe load and .trigger("load")

Know when a frame has loaded, and fire the handler manually for tests.

jQuery
$("#frame")
  .on("load", function () {
    $("#log").text("iframe loaded");
  })
  .attr("srcdoc", "<p>Hello from the frame</p>");

$("#fire").on("click", function () {
  $("#frame").trigger("load"); // test without reloading
});
Try It Yourself

How It Works

  1. Bind. The handler is attached before the frame content is set.
  2. Load. Setting srcdoc (or src) loads the frame and fires load.
  3. Trigger. .trigger("load") runs handlers without a network request.

Frequently Asked Questions

The load event is sent to an element when it and all its sub-elements have finished loading. It works for elements associated with a URL, such as images, scripts, frames and iframes, and for the window object. Bind it with .on("load", handler).
They share a name but are unrelated. .on("load", handler) listens for a resource finishing. .load(url) is an Ajax method that fetches HTML from a URL and inserts it into the matched elements. See the Ajax .load() tutorial for the second one.
The browser can finish loading as soon as src is set, especially for cached images. If the handler is not attached yet, you miss the event. Chain .on("load", fn) first, then .attr("src", url).
Document ready fires when the DOM has been parsed. The window load event fires later, after all images, stylesheets and frames have loaded. Use ready for DOM manipulation and window load when you need asset dimensions.
No. The load event does not bubble, so a delegated handler on a parent will not catch it from a child image. Attach the handler directly to each element, or to window for the page.
Common causes are binding after src was set, a cached image that loaded before the handler existed, or a broken URL (which fires error instead). Bind first, and check the img.complete property for cached images.
No. The .load(handler) event shorthand was deprecated in jQuery 1.8 and removed in 3.0. Use .on("load", handler) instead.

Next: .load() Method

See the removed event shorthand and how it differs from Ajax .load(url).

.load() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful