In my homepage, I'm trying to have a bunch of numbers go from 0 to their default value. Those numbers are all inside spans with a specific class. And, I have some jquery to animate them.
$(".number_up").each(function(){
num_to_up = parseInt($(this).text().replace(" ",""));
rythm = 3;
start = 0;
$(this).text(start);
element = $(this);
setInterval(function(){
if(start < num_to_up)
{
start = start+rythm;
$(element).text(start);
}
},0.001);
$(element).text(num_to_up);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="number_up">4 000</span>
<span class="number_up">4 000</span>
<span class="number_up">4 000</span>
<span class="number_up">4 000</span>
<span class="number_up">4 000</span>
But it only works for the last number in the list... all the previous ones stay at their default value. Any idea what I'm doing wrong ?