I'm trying to create a script that counts from ZERO to a number that will be fed via PHP, for example my HTML is
<h1 class = "myClass"> 500 </h1>
<h1 class = "myClass"> 424 </h1>
<h1 class = "myClass"> 424 </h1>
I would like to retrieve the values of elements that contain a specific class and count from Zero to themselves.
But I would like it done in Javascript, I've seen some Jquery Plugins But I would like to do the same thing in javascript, just like this example: https://codepen.io/shivasurya/pen/FatiB
Detail, it would be interesting for the count to end at the same time for small values and larger values.
I already tried something like:
function ng_count_number_animation (element) {
let select = window.document.querySelectorAll (element);
let start = 0;
let i;
for (i = 0; i <select.length; i ++) {
for (let y = 0; y <= Number (select [i] .innerHTML); y ++) {
select [i] .innerHTML = y;
}
}
}
ng_count_number_animation (". ng_count_number");
But it never works, I also used the Javascript setinterval to interval the count but it also doesn't work, always the result is ZERO in all classes.