Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  143] [ 2]  / answers: 1 / hits: 33447  / 12 Years ago, sun, may 13, 2012, 12:00:00

I want to change setInterval function time when my code is running.



I try this



<script type=text/javascript>
$(function () {
var timer;
function come() { alert(here); }
timer = setInterval(come, 0);
clearInterval(timer);
timer = setInterval(come, 10000);
});
</script>


First SetInterval does not work!


More From » jquery

 Answers
105

You're clearing the interval on the next line, so the first one wont work, as it gets cleared right away :



        timer = setInterval(come, 0);
clearInterval(timer);
timer = setInterval(come, 10000);


Also, as gdoron says, setting a interval of nothing isn't really valid, and not a really good idea either, use setTimeout instead, or just run the function outright if no delay is needed.



        come();
clearInterval(timer);
timer = setInterval(come, 10000);

[#85608] Friday, May 11, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eliezerc

Total Points: 286
Total Questions: 102
Total Answers: 102

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
eliezerc questions
Mon, Jun 20, 22, 00:00, 2 Years ago
Fri, Sep 4, 20, 00:00, 4 Years ago
Fri, Jul 3, 20, 00:00, 4 Years ago
;