Knowledge Walls
Laya
Hyderabad, Andhra Pradesh, India
window.clearInterval() Method in Window Object of Javascript Syntax with Examples
2782 Views
Usage 
The clearInterval() is used to clear interval which is mentioned in setinterval method.Example: If setinterval is used to display message at every particular time, then we can use clearinterval to stop display that particular message.
Syntax 
clearInterval(function);
Output
<button onclick="javascript:startIt();">Start</button>
<button onclick="javascript:stopIt();">Stop</button>

<input type="text" id="txt_current_time" size="50" />
var timer = null;
function doIt(){
  document.getElementById("txt_current_time").value = (new Date());
}

function startIt(){
   if (timer === null)
   timer = setInterval(doIt,1000);
}

function stopIt(){
   clearInterval(timer);
   timer = null;
}
Output 
It will display Start and Stop button.
Once you click start button, it will display time at every particular time interval in text box.

Sat Dec 06 2014 12:06:02 GMT+0530 (India Standard Time)

Once you click stop button, it will clear set values and stop the function.
Best Lessons of "Javascript Syntax with Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details