jQuery .load() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

.load(url [, data] [, complete]) fetches data from the server and places the returned HTML into the matched elements (since jQuery 1.0). It is the simplest jQuery Ajax shorthand for injecting HTML — roughly $.get() plus an automatic .html() update.

Syntax

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

jQuery
$("#result").load("ajax/test.html");

// With fragment selector (space + selector):
$("#result").load("ajax/test.html #container");

// POST when data is an object; GET otherwise
$("#feeds").load("feeds.php", { limit: 25 }, function () { /* complete */ });

// Empty selection → no Ajax request is sent
CallWhat it does
urlResource to fetch; may include a fragment selector after a space
dataObject/string → POST body; omitted → GET
completefunction(responseText, textStatus, jqXHR) — once per matched element
Matched elementEmpty set → request is never sent

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

Parameters

ParameterDescription
Step 1Select the container that should receive HTML (it must exist).
Step 2Call .load(url) for a GET, or .load(url, data) for a POST.
Step 3Optionally append a space + selector to load only a fragment.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Basic .load(url)

Official one-liner: load remote HTML into a container.

jQuery
$("#result").load("ajax/test.html");

// On click:
$("#run").on("click", function () {
  $("#result").load("https://httpbin.org/html");
});
Try It Yourself

How It Works

  1. Select. Target the element that should receive HTML.
  2. Fetch. jQuery sends a GET for the URL.
  3. Insert. On success, the response becomes the element’s HTML.

Example 2 — Load a Page Fragment

Space + selector keeps only part of the fetched document.

jQuery
$("#result").load("ajax/test.html #container");

// Live demo style:
$("#snippet").load("https://httpbin.org/html h1");
Try It Yourself

How It Works

  1. Split. Text after the first space is treated as a selector.
  2. Parse. jQuery parses the response with browser HTML rules.
  3. Keep. Only matching nodes are inserted; the rest is discarded.

Example 3 — Complete Callback

Run code after insertion — this is the updated DOM element.

jQuery
$("#result").load("ajax/test.html", function () {
  alert("Load was performed.");
});

$("#panel").load("https://httpbin.org/html h1", function (responseText, status, jqXHR) {
  $("#meta").text("Status: " + status + " | HTTP " + jqXHR.status);
});
Try It Yourself

How It Works

  1. Order. Complete runs after HTML insertion (on success).
  2. Args. You get responseText, textStatus, and jqXHR.
  3. Context. this is the element being updated.

Frequently Asked Questions

jQuery .load() is a collection method that fetches HTML from a URL and inserts it into each matched element. Call $("#panel").load("/partial.html") — on success jQuery sets the element’s HTML to the response. It is roughly equivalent to $.get() plus .html(), with an implicit success handler. Returns the jQuery collection for chaining.
$.get() is a global function that returns jqXHR — you update the DOM yourself. .load() is a method on a selection that injects returned HTML automatically. .load() also supports a URL fragment selector ("page.html #sidebar") that $.get() does not. Use .load() to inject HTML; use $.get() when you need to process the response yourself.
If you pass a data argument (plain object or string), jQuery uses POST and sends that data in the request body. With only a URL (and optional complete callback), .load() uses GET.
If the url string contains a space, the part after the first space is a jQuery selector applied to the fetched document. $("#result").load("article.html #comments") fetches article.html, extracts #comments, and inserts that into #result. Scripts in fragment loads are stripped and not executed.
Without a selector suffix, scripts pass through .html() and may execute before being discarded. With a selector suffix ("url #fragment"), scripts are stripped before insertion and do not run. Never .load() untrusted URLs — executed scripts have full page privileges.
If the jQuery collection is empty — for example $("#missing").load(url) when #missing does not exist — the Ajax request is not sent at all.

Next: jQuery.param() Method

Serialize objects and arrays for Ajax query strings and POST bodies.

jQuery.param() 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.

9 people found this page helpful