{ The format for this method is: window.setInterval("functionName()",time); The first parameter (“functionName()”) is the name of the function that you want to have executed. { Suppose I have a textarea. Stopwatch script We can display a stop watch showing hour, minutes and seconds. }); Start Improve this question. You have to store the timer id of the interval when you start it, you will use this value later to stop it, using the clearInterval function: This is based on CMS's answer. funciones Javascript – setInterval() clearInterval() setTimeout() – Parte 2. setInterval() This method is used to repeatedly execute a function at a set interval. In the previous chapter, we learnt how to use setTimeout method to execute a given function or code only once, by the given time interval. If you want to stop this function call, then you can use the clearInterval () method. } How can I remove a specific item from an array? Problem Declaring a setInterval() without keeping a reference to it (which is returned from the function call setInterval(), it returns an id number for the registered event). } else If the reload is started by a start/stop button, you can use the button itself. The clearInterval() method works in the same way as the clearTimeout() method. It merely schedules the specified javascript code to be run at the specified time. Output: Some more examples with setInterval() and clearInterval(). tm=window.setInterval('disp()',1000); javascript jquery setinterval. How To Recover End-To-End Encrypted Data After Losing Private Key? m.innerHTML='Stop'; It helps others too to see a correct answer amongst many answers. The question asked for the timer to be restarted on the blur and stopped on the focus, so I moved it around a little: Store the return of setInterval in a variable, and use it later to clear the interval. JavaScript clearInterval () As you have seen in the above example, the program executes a block of code at every specified time interval. The setInterval method returns a handle that you can use to clear the interval.