JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<button id="start">Start!</button>
<button id="end">End!</button>
<div id="targetDiv"></div>
</body>
JavaScript
var myStart = document.querySelector('#start'),
myEnd = document.querySelector('#end'),
myRepeat,
targetDiv = document.querySelector("#targetDiv");
function start() {
targetDiv.innerHTML += "Hello World<br>";
myRepeat = setTimeout(start, 1000)
}
function stop() {
//console.log("STOP");
clearTimeout(myRepeat);
}
myStart.onclick = start;
myEnd.onclick = stop;