I have a function with a setTimeout method. I want to stop it if the user executes another function (prevent "Alert" from happening). Is that possible?
function myFunction() {
setTimeout(function(){ alert("Hello"); }, 3000);
}
function stopThis() {
//how to stop myFunction()?
}
<p>Click the button to wait 3 seconds, then alert "Hello".</p>
<button onclick="myFunction()">Activate</button>
<button onclick="stopThis()">Stop it</button>