
Load in Jquery
In jQuery, the .load()
method is a powerful and easy way to load data from a server and insert it into a selected HTML element, without reloading the entire page. It’s part of jQuery’s AJAX functions.
? Syntax
$(selector).<div "#btn").click(function() { $("#result").load("demo.html"); });</script>
When the button is clicked, it loads the content of demo.html
into the #result
div.
? Example 2: Load Only a Part of a Page
You can load only a specific part of the page using a CSS selector after the file name:
$(<?phpecho "This is loaded from the server!";?>
? HTML
<button "#loadBtn").click(function() { $("#msgBox").load("data.php"); });</script>
? Summary
Method | What it does |
---|---|
.load() | Loads content from server into element |
.html() | Inserts raw HTML |
.ajax() | More customizable AJAX call |