.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.
Remember
$("#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
Pick a target element, pass a URL, optionally add data or a complete callback.
Select the container that should receive HTML (it must exist).
Call .load(url) for a GET, or .load(url, data) for a POST.
Optionally append a space + selector to load only a fragment.
Use the complete callback to react after insertion (or on error).
Only load trusted URLs — scripts may run when no fragment selector is used.
Piece
Required?
Role
url
Yes
Resource to fetch; may include a fragment selector after a space
data
Optional
Object/string → POST body; omitted → GET
complete
Optional
function(responseText, textStatus, jqXHR) — once per matched element
Matched element
Yes
Empty set → request is never sent
Pseudocode
Pseudocode
call $(selector).load(url [, data] [, complete])
if no elements matched:
do nothing (no Ajax)
return
split url on first space → remoteUrl, optionalFragmentSelector
if data is object/string:
method = POST
else:
method = GET
send Ajax request for remoteUrl
when response arrives:
if success or notmodified:
if fragmentSelector:
parse HTML, strip scripts, keep matching nodes
else:
set .html(response) // scripts may execute
if complete provided:
for each matched element:
call complete.call(element, responseText, textStatus, jqXHR)
Reference
Cheat Sheet
Keep these facts handy while injecting remote HTML.
Topic
Detail
Signature
.load(url [, data] [, complete])
Returns
jQuery collection (chainable)
Method
GET by default; POST when data is provided
Fragment
"page.html #id" — space + selector
Complete args
responseText, textStatus, jqXHR
this in complete
The DOM element being updated
Scripts
May run without selector; stripped with fragment selector
Empty set
No request sent
Since
jQuery 1.0
Try it
Live Preview
Load real HTML into a panel — full page, fragment only, or a failing URL.
Demo uses public HTTP APIs. Needs network access.
Panel
Ready — pick an action and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
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.
Once each. The callback fires once per matched element.
Example 4 — Error Handling in Complete
Official pattern: check status === "error" and show a message.
jQuery
$("#success").load("/not-here.php", function (response, status, xhr) {
if (status === "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
404 / network failure → status === "error"
#error shows status + statusText
#success may keep old content
How It Works
Always. Complete runs for success and failure.
Check. Inspect textStatus for "error".
Report. Use xhr.status and xhr.statusText.
UX. Show errors in a dedicated element so users notice the failure.
Example 5 — POST with a Data Object
Passing data switches the request to POST and sends the payload.
jQuery
$("#feeds").load("feeds.php", { limit: 25 }, function () {
alert("The last 25 entries in the feed have been loaded");
});
// Arrays in the POST body:
$("#objectID").load("test.php", { "choices[]": ["Jon", "Susan"] });
data object present → POST
Server HTML inserted into the target
complete runs after insertion
How It Works
Switch. A data object/string makes .load() use POST.
Serialize. Data is sent in the request body (via $.param()).
Insert. Returned HTML replaces the target contents on success.
Callback. The third argument is complete — not a jqXHR chain.
Edge Cases & Pitfalls
Check these before shipping partial HTML loads.
empty
Empty selection sends nothing
If the target selector matches no elements, jQuery skips the Ajax call entirely.
scripts
Scripts may execute without a fragment
Full-page loads can run script blocks. Fragment loads strip scripts. Only load trusted URLs.
cors
Same-origin policy applies
Cross-origin loads need CORS (or a same-origin proxy). Most browsers block plain cross-domain HTML fetches.
parse
Browsers filter markup while parsing
html, head, and body tags may be dropped during innerHTML parsing — inserted markup can differ from a full page view.
Compatibility
Browser Support
.load() has been part of jQuery since 1.0. It works wherever your loaded jQuery version can run Ajax. Cross-origin HTML still needs CORS. Prefer a current jQuery 3.x build for modern projects.
✓ Stable · jQuery 1.0+
jQuery .load()
Works in every browser that runs your loaded jQuery version. Same-origin (or CORS-enabled) HTML endpoints required.
100%With jQuery Ajax
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.load()Universal
Bottom line: Safe for everyday same-origin partials. Use fragment selectors for safer inserts, and always handle the complete status for errors.
Analysis
Performance Notes
Approach
Cost
Best for
Fragment .load(url #part)
Medium
Reuse full pages but insert a slice
Dedicated HTML partial
Cheaper
Small, purpose-built snippets
Lazy load on first open
Best UX
Tabs, modals, drawers
Fragment loads still download the whole remote document, then filter it. Prefer small server partials when you control the backend.
Remember
Key Takeaways
Role: simplest way to fetch HTML and inject it into matched elements.
Method: GET by default; POST when you pass data.
Fragment:"url #selector" inserts a slice; scripts are stripped.
Safety: empty targets skip Ajax; only load trusted HTML.
One line:.load() is jQuery’s Ajax shorthand for “get HTML and put it here.”
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.