Swim89 Swim89 - 2 months ago 16
jQuery Question

jQuery add/remove Class with fadeIn/Out

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

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.

Comments