Showing posts with label clearinterval. Show all posts
Showing posts with label clearinterval. Show all posts

Saturday, November 11, 2017

JavaScript Interval Example | SetInterval And ClearInterval

JavaScript setInterval & clearInterval example:



var i = 3;

var interval = setInterval(function() {
  if (i > 0) {
    $("div").html("Running " + i--);
  }
  else {
    clearInterval(interval);

    $("div").html("Stopped");
  }
}, 2000);


JSFiddle example link