CLiown
CLiown

Reputation: 13853

Run jQuery after another jQuery script

Im using curl to fetch the HTML from anothe web page and display on one of my pages:

$("document").ready(function() {

    $("#content").load("curl.php .auction_list_closed");

});

Once the content is returned I want to have another script run. How can I run another line of jQuery once the content has been loaded?

Upvotes: 1

Views: 1811

Answers (4)

Teja Kantamneni
Teja Kantamneni

Reputation: 17482

add your code in the callback method

$("#content").load("curl.php .auction_list_closed", function() {
  //do your stuff here.
});

Upvotes: 3

Rob
Rob

Reputation: 6891

Not quite sure, but i believe you can simply add an callback function. More info can be found here

For example:

$("document").ready(function() {

    $("#content").load("curl.php .auction_list_closed", function() {alert("data was loaded")});

});

Upvotes: 1

hunter
hunter

Reputation: 63562

You can pass a callback to the load() method as a parameter: http://api.jquery.com/load/

$("#content").load("curl.php .auction_list_closed", function() { 
    // do work
});

or

$("#content").load("curl.php .auction_list_closed", myCallback);

function myCallback() {
    // do work
}

Upvotes: 2

Dutchie432
Dutchie432

Reputation: 29170

The .load() function accepts, as the second parameter, a function which is executed once completed.

$("document").ready(function() {
    $("#content").load("curl.php .auction_list_closed", function(){
         startSecondScript();
    });
});

Upvotes: 4

Related Questions