on-internet
← Community

counterup the numbers with setInterval (jQuery)

Stack Overflow ·

I'm trying to counter up the numbers defined in data attribute with set interval. My code is here. $( ".number" ).each(function(index) { var INCREMENT = $(this).data('increment'); var START_VALUE = 0; var count = 0; count = INCREMENT; $(this).html(count); window.setInterval( function(index){ count += INCREMENT; $('.number').html(count); }, 1000); }); I'm able to get the numbers initially, but with setInterval, all using the first number in the array. WORKING FIDDLE

Comments

Sign in or sign up to comment and upvote.

No comments yet.