Questions tagged [clearinterval]

The Javascript clearInterval() method clears a timer set with the setInterval() method.

The Javascript clearInterval() method clears a timer set with the setInterval() method.
The ID value returned by setInterval() is used as the parameter for the clearInterval() method.

660 questions
216
votes
1 answer

Can clearInterval() be called inside setInterval()?

bigloop=setInterval(function () { var checked = $('#status_table tr [id^="monitor_"]:checked'); if (checked.index()===-1 ||checked.length===0 || ){ bigloop=clearInterval(bigloop); …
yvonnezoe
  • 7,129
  • 8
  • 30
  • 47
153
votes
13 answers

Code for a simple JavaScript countdown timer?

I want to use a simple countdown timer starting at 30 seconds from when the function is run and ending at 0. No milliseconds. How can it be coded?
Michael Swarts
  • 3,813
  • 8
  • 31
  • 41
91
votes
5 answers

Javascript setInterval function to clear itself?

myInterval = setInterval(function(){ MyFunction(); },50); function MyFunction() { //Can I call clearInterval(myInterval); in here? } The interval's not stopping (not being cleared), if what I've coded above is fine then it'll help me look…
user1017882
56
votes
4 answers

Are clearTimeout and clearInterval the same?

When working on some Javascript for a web application, I noticed that I had used setTimeout, but I had tried to clear it with clearInterval and it stopped the timeout from occurring in Google Chrome and Internet Explorer 9. Are clearTimeout and…
Ivan
  • 10,052
  • 12
  • 47
  • 78
54
votes
6 answers

clearInterval() not working

Possible Duplicate: JS - How to clear interval after using setInterval() I have a function that changes the font-family of some text every 500 ms using setInterval (I made it just to practice JavaScript.) The function is called by clicking on an…
Matt Sanchez
  • 583
  • 1
  • 6
  • 10
36
votes
7 answers

clearInterval in React

I'm new at React and I was trying to create a simple stopwatch with a start and stop buttons. I'm banging my head against the wall to try to clearInterval with an onClick event on Stop button. I would declare a variable for the setInterval and then…
Lucas
  • 361
  • 1
  • 3
  • 3
29
votes
5 answers

How to clearInterval with unknown ID?

Say someone (evil) has set us a timer with setInterval, but we don't know its ID (we don't have the reference to the object, that setInterval is returning, nor its value) (function(){ setInterval(function(){console.log('pwned')}, …
mykhal
  • 19,175
  • 11
  • 72
  • 80
15
votes
3 answers

How to use clearInterval() in Angular 4

I am trying to use setInterval in my Angular 4 app. const inter = setInterval(() => { // logic resulting in exitCondition if(exitCondition) { clearInterval(inter); } }, 1000); This set up works fine in vanilla javascript, but…
Kevin Shi
  • 496
  • 1
  • 7
  • 18
15
votes
6 answers

How do I correctly use setInterval and clearInterval to switch between two different functions?

For practice I am trying to display a number that increments from 0 - 9, then decrements from 9 - 0, and infinitely repeats.The code that I have so far seems to be close, but upon the second iteration the setInterval calls of my 2 respective…
Ian Campbell
  • 2,678
  • 10
  • 56
  • 104
12
votes
8 answers

Clear all setIntervals

I'm using setIntervals within an each() function like so $(".elements").each(function() { setInterval(function() { }, 1000); }); Obviously a setIntervals is created for each element. My question is: How do I clear all the setIntervals when…
user3758078
9
votes
2 answers

How to remove all running $interval in AngularJS?

Hi i want to remove all running $interval in Angular. in my page there are many $interval and on button click i want to remove all interval.How will i do it . Any help is appreciated.
Rituraj ratan
  • 10,260
  • 8
  • 34
  • 55
9
votes
2 answers

setTimeout appears to execute too fast

I've been fiddling around with setTimeout and setInterval, and I cannot get the code to execute the way I would like it to. My goal is to create a setInterval, which calls once every three seconds, and have it clear after ten seconds. However, when…
Nick Litwin
  • 2,875
  • 2
  • 13
  • 13
8
votes
3 answers

restarting a setInterval

So I have a timer rotates a set of images ever 5 seconds. Therefore, I am running this upon document launch. $(document).ready(function() { var intervalID=setInterval(function(){ rotate(); }, 5000); }); The Rotate function simply just…
user646655
  • 131
  • 1
  • 6
7
votes
2 answers

why setInterval() cycle goes faster every time?

I'm building a custom slider on Javascript , and I want that every time the user clicks on a div of the slider, the slider should stop for X seconds. My code is: $(document).ready(function () { var ciclo; var index_slide = 1; function…
user1230041
6
votes
3 answers

JS clearInterval or window.clearInterval?

Javascript has setInterval and clearInterval functions for handling asynchronous function calls. Is there a difference between clearInterval(handle) and window.clearInterval(handle)? I've seen it being used both ways.
TheOne
  • 10,819
  • 20
  • 81
  • 119
1
2 3
43 44