JSFiddle - React, Tailwind, and code Playground
HTML
<p id="test">Test</p>
<button id="foo">Click</button>
JavaScript
var timerId = 0;
function doSomething() {
var test = document.getElementById("test");
test.innerText += ' Test';
}
function onmousedown(ev) {
doSomething();
timerId = setInterval(function () {
doSomething();
}, 1000);
}
function onmouseup(ev) {
clearInterval(timerId);
}
var obj = document.getElementById("foo");
obj.addEventListener("mousedown", onmousedown);
obj.addEventListener("mouseup", onmouseup);