JSFiddle - React, Tailwind, and code Playground

by tjerabek

HTML

<div class="counter" data-start="1" data-end="15">
15
</div>

JavaScript

$(document).ready(function(){
    $('.counter').each(function(){
        $this = $(this);
        
        var start = $this.data('start');
        var end = $this.data('end');
        
        var i = start;
        $this.text(i);
        var interval = setInterval(function(){
            $this.text(i);
            i++;
            
            if(i>end){
                clearInterval(interval);
            }
        }, 50);
        
    });
});