Search code examples
jqueryfunctionloadclicklive

Executing code after a process is done - jQuery


I want to run:

$(".left").load("created.php");

after:

$("#placeholder").load("create.php")

I tried the following, but it didn't work:

$("#create").live("click", function() {
 if($("#placeholder").load("create.php")) {
  $(".left").load("created.php");
 }
})

Solution

  • The jQuery load() function runs asychronously. You need to use a callback function to run code after the first load completes.

    The following code should suffice:

     $("#create").live("click", function() {
       $("#placeholder").load("create.php", function() {
         $(".left").load("created.php");
       });
     });
    

    Enjoy!