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.
Window. The legacy shorthand was most often used on window.
Modern.$(window).on("load", fn) is the exact replacement.
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");
.load("url") → Ajax request, HTML inserted
.on("load", handler) → event listener
.trigger("load") → fire the event handlers
How It Works
Ajax..load(url) requests HTML and injects it into the element.
Event..on("load") runs code when a resource finishes loading.
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.