.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
Call
What it does
url
Resource to fetch; may include a fragment selector after a space
data
Object/string → POST body; omitted → GET
complete
function(responseText, textStatus, jqXHR) — once per matched element
Matched element
Empty set → request is never sent
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Select the container that should receive HTML (it must exist).
Step 2
Call .load(url) for a GET, or .load(url, data) for a POST.
Step 3
Optionally append a space + selector to load only a fragment.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters 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");
});
HTML inserted into #panel
Callback runs after post-processing
this === each matched DOM element
How It Works
Order. Complete runs after HTML insertion (on success).
Args. You get responseText, textStatus, and jqXHR.
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.