I’ve created a function to animate out a div on click and I need to remove a class and an attribute after the animation has completed.

Here’s the code:

$(‘.close__overlay’).on(‘click’, function(){
$(‘.fw__bio-container’).animate({
right: “-200%”
}, 50, function() {
// Post-animation callback function, add the required code here
$(‘.fw__bio-container’).removeClass(“active”).removeAttr(“style”);
});
});
But it’s not working as expected. The animation starts before the overlay just disappears.
According to my reading and searches, this is what I’m supposed to do, so what am I doing wrong?

TIA!

Have you tried using setTimeout?
$(“.close__overlay”).on(“click”, function () {
$(“.fw__bio-container”).animate(
{
right: “-200%”
},
50,
function () {
setTimeout(function () {
$(“.fw__bio-container”).removeClass(“active”).removeAttr(“style”);
}, 300);
}
);
});
That did it, thank you!
No but I will. I’d seen it but then I’d seen that it wasn’t good use.

source