JSFiddle - React, Tailwind, and code Playground
HTML
<div id="showtm1" style="font-size:21px; font-weight:800;">0:0</div>
<button onclick="compteur1.start('showtm1')">Start</button>
<button onclick="compteur1.stop('showtm1')">Stop</button>
<div id="showtm2" style="font-size:21px; font-weight:800;">0:0</div>
<button onclick="compteur2.start('showtm2')">Start</button>
<button onclick="compteur2.stop('showtm2')">Stop</button>
JavaScript
var Compteur = function( id ) {
var seconds = 0,
startchron = 0;
function chronometer( id ) {
if(startchron == 1) {
seconds += 1;
document.getElementById( id ).innerHTML = seconds;
setTimeout(function () {chronometer( id );}, 1000);
}
}
this.start = function( id ) {
startchron = 1;
chronometer( id );
};
this.stop = function( id ) {
startchron = 0;
};
};
var compteur1 = new Compteur( "showtm1" );
var compteur2 = new Compteur( "showtm2" );