How can I finish a setInterval?

Asked

Viewed 294 times

0

Hello, I wonder if it is possible to stop a setinterval after a certain time, if possible, as?

2 answers

3


2

Only use clearInterval() Example:

var myVar = setInterval(myTimer, 1000);

function myTimer() {
  var d = new Date();
  var t = d.toLocaleTimeString();
  document.getElementById("demo").innerHTML = t;
}

function myStopFunction() {
  clearInterval(myVar);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.