jQuery add/remove Class with fadeIn/Out

Swim89 picture Swim89 · Mar 31, 2013 · Viewed 81.3k times · Source

I would to apply a fadeIn effect to a addClass function..and fadeOut to removeClass...

Can you help me?

This is my code

$('#loader'+idTurno).addClass('loader');

...

$('#loader'+idTurno).removeClass('loader');

Answer

What have you tried picture What have you tried · Mar 31, 2013

Fade In:

$("#loader").fadeIn("slow", function() {
    $(this).addClass("loader");
});

Fade Out:

$("#loader").fadeOut("slow", function() {
    $(this).removeClass("loader");
});

As another user said, you may want to look into using toggleClass.