Skip to content
Advertisement

javascript clearInterval() function is not working

JavaScript

//I want when user press key interval stop , than new interval start again but old interval cant stop

Advertisement

Answer

You have two problems.

  • You have var interval inside your function so it gets reset every time the function runs.
  • setTimeout will call a function, once, after a time period. It won’t clear an interval, you need clearInterval for that.
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement