How to stop a setInterval() function? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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
4 Respostas
+ 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