views:

145

answers:

2

I'm trying to do a little javascript trick to fade out a div, replace its content, and fade it back in. The .html event is replacing the content before the fadeOut is complete...

$("#products").fadeOut(500)
              .delay(600)
              .html($("#productPage" + pageNum).html())
              .fadeIn(500);

It appears that the .html() is not being delayed by the .delay() method.

+1  A: 

you could change it to make the change when the fadeOut is completed using the fcallback function parameter.

so it becomes:

$("#products").fadeOut(500, function() {
    $(this).html($("#productPage" + pageNum).html());
    $(this).fadeIn(500);
});
Alastair Pitts
+3  A: 

delay will work for your case when used with the queue like this:

$("#products").fadeOut(500)
    .delay(600)
    .queue(function(n) {
        $(this).html("hahahhaha");
        n();
    }).fadeIn(500);​

Try it here: http://jsfiddle.net/n7j8Y/

karim79
+1 my `chain()` was actually the `queue()`! ;)
Frankie
+1 There's a jQuery for that.
Peter Ajtai
Two things - Why doesn't `.delay()` work on `.html()` and what does `n()` do?
Derek Adair