JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> timer </title>
</head>
<body>
<input type="text" id="theField" value="1">
<button onclick="start_timer();"> start timer </button>
<button onclick="stop_timer();"> stop timer </button>
</body>
</html>
JavaScript
function start_timer(){
document.getElementById('theField').value++;
timerVariable = setTimeout('start_timer()',1000);
console.log('set timeout return value: ' + timerVariable);
}
function stop_timer(){
clearTimeout(timerVariable);
console.log('clearing timeout: ' + timerVariable);
}