0

Hi so I have made a setInterval and as many before me I don't seem to be able to stop it.

I looked at the great internet and I found my solution - I thought - through clearInterval and a timer variable to make sure to stop the interval.

However I still don't seem to be able to stop my setInterval.

Anyhow, any help is appreciated and here is my JsFiddle

Michael Tot Korsgaard
  • 3,892
  • 11
  • 53
  • 89

1 Answers1

2

You did not assign your interval to a variable. If you do so you can then clear the interval by passing the variable to the clearInterval function:

Here is an example:

// start an interval
var myInterval = setInterval(function(){ ... }, 1000);

// stop an interval
clearInterval(myInterval);
nils
  • 1,668
  • 14
  • 15