JSFiddle - React, Tailwind, and code Playground
HTML
Timer 1: <span class="timer"></span><button>Start</button><br>
Timer 2: <span class="timer"></span><button>Start</button><br>
Timer 3: <span class="timer"></span><button>Start</button><br>
JavaScript
(function(){
$.fn.multitimer = function(){
var methods = {
init: function(i, el){
var o = this;
$(el).on('click', function(){
o.start(i, $(this).hide().prev('span').text(0));
});
},
start: function(i, el){
this.clear(i);
this.increase(el);
this.intervals[i] = setInterval(this.increase, 1000, el);
},
increase: function(el){
el.text(parseFloat(el.text()) + 1);
},
clear: function(i){
clearInterval(this.intervals[i]);
},
intervals: []
};
return this.each(function(i){ methods.init(i,this); });
};
})();
$('button').multitimer();