Here is the plunker
$(document).ready(function(){
$('#btn-animate').click(function(){
animate();
});
$('#btn-remove').click(function(){
$('.to-animate').removeClass('animate');
});
function animate(){
$('.to-animate').removeClass('animate');
$('.to-animate').addClass('animate');
}
});
Here if I click on "ANIMATE" button it adds an 'animate' class to the div and animates it(changes color). But if you click again it tries to remove the class 'animate' and add it back so that the animation triggers again.
But it is not happening. Strangely if I click the "REMOVE" button to remove the 'animate' class and then with the "ANIMATE" button add the class it animates again.
Can anyone explain why first button is failing to give the required result? And how can I get the animation be triggered every time I click the "ANIMATE" button?