11 January 2015

Clearing setInterval()

When you initiate the setInterval method, an interval ID is returned. If you retain that interval ID in a variable, you can later pass it into the clearInterval method to stop the interval:

Example:

  var intervalID = setInterval(startClock, 1000);
  resetTimer()

  $("#stop").click(function() {
    clearInterval(intervalID);
  });