JSFiddle - React, Tailwind, and code Playground

cancelling timeouts

by nilloc

HTML

<div id="tester">tester</div>

JavaScript

let tester = document.getElementById('tester');



let turnRed = function(){
	tester.style.color = '#cc0000';
}

tester.timeout = setTimeout(turnRed, 3000);

tester.onclick = function(evt){
  console.log('clicked', tester.timeout, clearTimeout(tester.timeout));
  /* clearTimeout(timeout) */;
}