The below JQuery Jquery Start count and Brack timer clearTimeout()
<!DOCTYPE html>
<html>
<body>
<button onclick="startCount()">Start count!</button>
<input type="text" id="txt">
<button onclick="stopCount()">Stop count!</button>
<p>
Click on the "Start count!" button above to start the timer. The input field will count forever, starting at 0. Click on the "Stop count!" button to stop the counting. Click on the "Start count!" button to start the timer again.
</p>
<script>
var c = 0;
var t;
var timer_is_on = 0;
var myCounter = 0;
function timedCount() {
document.getElementById("txt").value = c;
c = c + 1;
t = setTimeout(timedCount, 1000);
myCounter = myCounter + 1
if(myCounter == 4)
{
c = 0;
t;
timer_is_on = 0;
myCounter = 0;
clearTimeout(t);
timer_is_on = 0;
}
}
function startCount() {
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
c = 0;
t;
timer_is_on = 0;
myCounter = 0;
clearTimeout(t);
timer_is_on = 0;
}
</script>
</body>
</html>