jQuery load(), it is a very simple method but powerful AJAX method. The load() method is used to load data from server and puts the returned value into selected element without loading the entire page. This jQuery load method has 3 parameters, including URL, data and Callback.

Syntax for load()

$(selector).load(URL, data, callback);

URL parameter is to metion the url that need to load. Likewise, data parameter is helps to specify a colletion of querystring value pairs to send with the request. Finally callback is an optional one, which is the name of a funcion to be executed after the load() method is completed.

Example: 1


The above example loads the data of the file “demo_ld.txt” into a specific <div> element.

Example: 2

$(“#div”).load(“demo_ld.txt #p”);

This will loads the content of the element wit id=”p” in the file into a particular div element.

The optional callback parameter also has different parameters, such as responseTxt, statusTxt and xhr.

Example: 3
  $(“#div1”).load(“demo_test.txt”function(responseTxt, statusTxt, xhr){
    if(statusTxt == “success”)
      alert(“External content loaded successfully!”);
    if(statusTxt == “error”)
      alert(“Error: “ + xhr.status + “: “ + xhr.statusText);
Complete example for load() method
        <script src= 
            body { 
                text-align: center; 
            .gfg { 
                font-weight: bold; 
                color: green; 
            .geeks { 
                color: black; 
            #div_content { 
                font-size: 40px; 
                font-weight: bold; 
                color: green; 
        <div id="div_content"> 
            <div class = "gfg">GeeksforGeeks</div> 
            <div class = "geeks">A computer science portal for geeks</div> 
        <button>Change Content</button> 

Leave a Reply

Your email address will not be published. Required fields are marked *