How to stop the runing of the setTimeout() function in JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
  
<head></head>
  
<body>

<p id="p-id"></p>

<button onclick="clearTimeout(i)">Stop</button>
<script>

var i = setInterval(function () {clock()}, 1000);
 
function clock() 
{
    var d = new Date();
    document.getElementById("p-id").innerHTML = d.toLocaleTimeString();
}
 
/*
run:
  
12:49:15 PM ... 12:49:16 PM  ... 12:49:17 PM  ...
    
*/

</script>

</body>
  
</html>

 



answered Jul 23, 2015 by avibootz

Related questions

1 answer 133 views
3 answers 218 views
1 answer 138 views
1 answer 156 views
1 answer 158 views
...