Javascript examples for Browser Object Model:Window setTimeout
Call clearTimeout() via another function
<html> <head></head> <body> <button onclick="start()">Try it</button> <button onclick="end()">click me</button> <script> var fun;/*ww w .j av a 2 s . c om*/ function start() { fun = setTimeout(function(){ console.log("Hello"); }, 3000); } function end(){ clearTimeout(fun); } </script> </body> </html>