0

I know this can't be that difficult, but I swear I can't find a straight forward answer to this. I have the following javascript/jquery function that starts a timer:

function startTimer() { (function ($) {
    //timer for the box
    window.timer = window.setInterval(function() {
       $(".region-brand-window").timer();
    }, 10000);

    jQuery.fn.timer = function() {
       changeBrandOnTimer();
    }
})(jQuery); }   

How do I stop this thing? And I don't mean pause. I mean turn it off from another function.

1
  • 2
    clearInterval(timer) should do it. Or if timer is defined in the scope your using it in, you could do clearInterval(window.timer) Commented Oct 17, 2012 at 20:29

4 Answers 4

2
clearInterval(window.timer);

Should do it.

Sign up to request clarification or add additional context in comments.

Comments

2

To cancel an interval, you would use:

clearInterval(window.timer);

FYI, if it was a timeout you would use clearTimeout() in the same way.

Comments

1

use window.clearInterval(intervalID)

window.clearInterval(window.timer)

Comments

1

call stopTimer whenever you want to stop timer.

    function startTimer() { (function ($) {
        //timer for the box
        window.timer = window.setInterval(function() {
           $(".region-brand-window").timer();
        }, 10000);

        jQuery.fn.timer = function() {
           changeBrandOnTimer();
        }
    })(jQuery); } 

   function stopTimer(){
           clearInterval(timer );
   }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.