tags:

views:

28

answers:

2
        $("#show-sidebar").click(function () {
            $(this).fadeOut("fast");

            $("#sidebar").animate({
                marginLeft: "0"
            }, "fast");

            $("#content").toggleClass("full");
        });

What I wanto to do is, I guess, pretty simple: For each of this actions to execute, I need it to wait untill the previous one finishes.

+3  A: 
    $("#show-sidebar").click(function () {
        $(this).fadeOut("fast", function() {
           $("#sidebar").animate({
               marginLeft: "0"
           }, "fast", function() {
                 $("#content").toggleClass("full");
            });
        });
    });
alex
+5  A: 

Put each one within a callback function for the previous action:

$("#show-sidebar").click(function () {
    $(this).fadeOut("fast", function() {
      $("#sidebar").animate({
          marginLeft: "0"
      }, "fast", function() {
        $("#content").toggleClass("full");
      });
    });
});
casablanca