0

I want the numbers inside the list to animate so it displays different number for that duration when button is on click state. But it seems jquery animation is not working inside of it for loop.

$("button").on("click",function(){

 for(var i=0; i < 2; i++ ){

  $({value: $(".number").eq(i).text()}).animate({value: data1[i]},{
       duration: 500,
       easing: 'swing',
       step: function(){
         $(".number").eq(i).text(parseInt(this.value));
       }
     });
  }

});

This is my code example.

1 Answers1

0

As soon as the loop completes i is 3, ergo all usages of i in the animation callback will be the wrong value.