jQuery .load() Method

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

Definition

The .load(handler) event shorthand (1.0–2.x) bound a function to the browser load event on windows, images and frames. It was deprecated in 1.8 and removed in jQuery 3.0. Use .on("load", handler) instead. In jQuery 3.x the name .load() belongs only to the Ajax method .load(url), which fetches HTML into an element.

Syntax

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

jQuery
// Removed in jQuery 3.0 (worked in 1.x / 2.x)
$(window).load(function () { /* page loaded */ });
$("#book").load(function () { /* image loaded */ });
$("#book").load({ label: "cover" }, handler);  // with eventData
$("#book").load();                             // trigger

// Modern replacements
$(window).on("load", handler);
$("#book").on("load", handler);
$("#book").on("load", { label: "cover" }, handler);
$("#book").trigger("load");

// Different method - Ajax (still supported)
$("#box").load("/partial.html #content");
CallWhat it does
.load(handler)Removed — use .on("load", handler)
.load(eventData, handler)Removed — use .on("load", eventData, handler)
.load() (no args)Removed trigger — use .trigger("load")
.load(url, data, complete)Ajax method — a different API that still exists

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

Parameters

ParameterDescription
handlerfunction(event) that runs when the element has loaded. Migrate to .on("load", handler).
eventDataOptional object exposed as event.data. Migrate to .on("load", eventData, handler).
urlUsed only by the Ajax .load(url) method, not by the event shorthand.

Return Value

Return ValueDescription
jQuery objectThe old shorthand returned the original collection for chaining. .on() and .trigger() do the same.

jQuery Examples

Example 1 — Migrate .load(handler) to .on("load")

Rename the method and keep the handler. Bind before setting src.

jQuery
// Before (jQuery 1.x / 2.x)
// $("#book").load(function () { ... }).attr("src", "photo.png");

// After
$("#book")
  .on("load", function () {
    $("#log").text("Image loaded.");
  })
  .attr("src", "photo.png");
Try It Yourself

How It Works

  1. Find. Look for .load(function ...) calls on images and frames.
  2. Rename. Replace with .on("load", function ...).
  3. Order. Keep the handler before .attr("src").

Example 2 — $(window).load() to $(window).on("load")

The most common legacy use — running code after the whole page has loaded.

jQuery
// Before
// $(window).load(function () { ... });

// After
$(window).on("load", function () {
  $("#log").text("All page assets loaded.");
});

// With eventData
$(window).on("load", { page: "home" }, function (event) {
  $("#log").append(" (" + event.data.page + ")");
});
Try It Yourself

How It Works

  1. Window. The legacy shorthand was most often used on window.
  2. Modern. $(window).on("load", fn) is the exact replacement.
  3. Data. Pass an object as the second argument for event.data.

Example 3 — Event Form vs Ajax .load(url)

Two different methods share one name. A string argument means Ajax; an event means .on("load").

jQuery
// Ajax: fetch HTML and insert it (still supported)
$("#result").load("/snippets/card.html");

// Event: react when an image finishes loading
$("#book").on("load", function () {
  $("#log").text("Image ready.");
});

// Legacy trigger -> modern trigger
$("#book").trigger("load");
Try It Yourself

How It Works

  1. Ajax. .load(url) requests HTML and injects it into the element.
  2. Event. .on("load") runs code when a resource finishes loading.
  3. Trigger. Use .trigger("load"), not a no-argument .load().

Frequently Asked Questions

It was a shortcut for .on("load", handler). .load(handler) and .load(eventData, handler) bound a function to the browser load event on windows, images and frames, and .load() with no arguments triggered the event. It existed from jQuery 1.0.
Both. It was deprecated in jQuery 1.8 and removed in jQuery 3.0. In jQuery 3.x, .load() refers only to the Ajax method that takes a URL.
Replace .load(fn) with .on("load", fn), .load(data, fn) with .on("load", data, fn), and a no-argument .load() with .trigger("load"). Attach the handler before setting src.
The event shorthand listened for a resource finishing. Ajax .load(url) requests HTML from a URL and inserts it into the matched elements. They share a name, which is why the event form was removed. Use .on("load") for events.
Because the event shorthand no longer exists. The name .load() now means Ajax, so passing a function does not bind a load handler. Use $(window).on("load", handler).
Yes, but only the event shorthand in those versions, and it is deprecated since 1.8. Migrate to .on("load") now so you can upgrade to jQuery 3.x without changes.

Next: Resize Event

Learn how to listen for viewport size changes with .on("resize").

Resize Event 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