0

How to stop a setInterval() function?

I used one calling setInterval(timer,1000) but when i try to stop it, the clearInterval() don't work

26th Sep 2019, 12:27 PM
Alan Christian
Alan Christian - avatar
5 ответов
+ 4
Example: var st = setInterval(timer,1000) clearInterval(st) It will work.
26th Sep 2019, 1:02 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
Yes, when you clear the interval, you have to tell inside () what interval you are clearing.
26th Sep 2019, 4:34 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 1
So... I have to assign the interval into a variable, not just declare the set and after the clear?
26th Sep 2019, 4:10 PM
Alan Christian
Alan Christian - avatar
+ 1
Okay, thanks
26th Sep 2019, 4:40 PM
Alan Christian
Alan Christian - avatar