How to clears a timer set with clearInterval() in JavaScript

1 Answer

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

<p id="pid"></p>

<button onclick="StopTime()">Stop time</button>

<script> 
var interval = setInterval(function(){ ShowTime() }, 1000);

function ShowTime() {
    var dt = new Date();
    var tm = dt.toLocaleTimeString();
    document.getElementById("pid").innerHTML = tm;
}

function StopTime() {
    clearInterval(interval);
}


/*
run:
 
09:51:08
 
*/
</script>

</body>
</html>

 



answered May 3, 2017 by avibootz

Related questions

1 answer 234 views
1 answer 286 views
1 answer 244 views
1 answer 242 views
1 answer 71 views
1 answer 216 views
...