Chud37 Chud37 - 6 months ago 17
jQuery Question

Correct way to use FadeOut callbacks

What is the correct way to fadeout, and then fadeIn again?

Is it:

$("iframe#youtube").fadeOut(500, function() {
$(this).attr("src","www.youtube.com/embed/"+data.url+"?rel=0&autoplay=1");
$(this).fadeIn(500);
});


Or:

$("iframe#youtube").fadeOut(500, function() {
$(this).attr("src","www.youtube.com/embed/"+data.url+"?rel=0&autoplay=1");
}).fadeIn(500);

Answer
$("iframe#youtube").fadeOut(500, function() {
    $(this).attr("src","www.youtube.com/embed/"+data.url+"?rel=0&autoplay=1").fadeIn(500);
});

First before any change you need to fadeout and hide content. Made all changes and after that to display with fade in. That's it.