X

LATEST #JQUERY NEWS

Using the jQuery .load() Method


jQuery’s .load() method is used to load data from a server (from a directory within your domain) and then place the loaded data into your selected element. The load method syntax looks a lot like many of the other commonly used jQuery methods, except that it can take a lot more parameters than your standard jQuery method. Here’s a basic example of how it works:

$(".main").load("/demos/div-text.html");

The code above will load the contents of the div-text.html file and place it into the .main div. The basic syntax and concept of the method is fairly simple and straightforward, but it’s also a good idea to acquaint yourself with the parameters that the method will take. The official syntax looks like this:

$("selector").load("url", data, function(responseText, textStatus, xhr));

In the example above, url obviously represents the url of the data you’re trying to load. Data represents any data to send to the server along with your request. Function represents any callback function you’d like to execute, where response contains the result data from your request, status contains the status of your request (whether it’s successful or not), and xhr represents the XMLHttpRequest object.

Recently Published

article image
»

jQuery Snippets: How to Add/Remove Classes After Delay

In your projects, there can often be instances of wanting to change ...

article image
»

jQuery Snippets: Back to Top Button

One common way to use jQuery is to add a useful and functional ...

article image
»

jQuery .on() Method: the Issue of Dynamically Added Elements

The jQuery .on() method is the recommended way for attaching events ...

article image
»

How to Use jQuery to Test CSS3 Browser Support

The tricky thing about using CSS properties (especially newer ones ...

article image
»

jQuery Snippets: Check/Un-Check All Function

This easy-to-implement jQuery code snippet is super useful, and can ...

article image
»

Useful jQuery Code Snippets for Handling CSS

If you’re not already familiar with code snippets, they are ...

article image
»

Using Method Chaining in jQuery

Using method chaining in jQuery helps to ensure that your code stays ...

article image
»

jQuery’s .children() Method

Just like in CSS, it’s possible to use jQuery to select the ...

article image
»

jQuery’s .click() Method

With jQuery, it’s super easy to make something happen as a result ...