jQuery — Load
Basic load()
$("#content").load("page.html");
load with Callback
$("#content").load("page.html", function(response, status, xhr) {
if (status === "success") {
console.log("Content loaded");
}
});
Load with Selector
// Load only #main from page.html
$("#content").load("page.html #main");
Load with Data
$("#results").load("search.php", { query: "jQuery" });
Practical: Partial Page Updates
// Load sidebar content
$("#sidebar").load("/partials/sidebar.html");
// Load on click
$(".load-more").click(function() {
$("#content").load("next-page.html");
return false;
});
AJAX Loading Indicator
$("#content")
.html("<p>Loading...</p>")
.load("page.html", function() {
console.log("Done");
});
load() vs $.ajax()
| Feature | load() | $.ajax() |
|---|---|---|
| Method | GET only | Any |
| Target | Always inserts HTML | Full control |
| Complexity | Simple | Advanced |
Mini Practice
- Load HTML into a div
- Load with a selector filter
- Show a loading state during load
- Load content on button click
Up Next
Continue with Get and Post — simplified AJAX requests.
Related Topics
Frequently Asked Questions about Load
What is Load in jQuery?
Load is a fundamental concept in jQuery. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Load?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Load.
Why is Load important in jQuery?
Load is essential for jQuery development. Understanding this concept will help you write better code and solve real-world problems more effectively.