JSFiddle - React, Tailwind, and code Playground
HTML
<p id="time"></p>
<button id="startstop">Start/stop</button>
JavaScript
// assuming you declared ti and t out here, cuz I hope they're not global
var t = 0;
var ti;
var time = null;
var running = false;
function startpause() {
clearTimeout(ti);
if(!running) {
ti = setTimeout(tim,1000);
running = true;
} else {
running = false;
}
}
function tim() {
time.innerHTML = t;
t = t + 1;
ti = setTimeout(tim,1000);
}
$(document).ready(function() {
$('#startstop').click(startpause);
time = $('#time')[0];
});