jQuery setInterval and setTimeout

Submitted by:Jhon Jhon

Date added:04 January, 2014

Category:jQuery

Example shows how to set Interval and set Timeout in jQuery

Tags: jquery time , set interval , set timeout

Code Snippet:

var timer = setInterval(function(){
if(someConditionIsTrue){
clearTimeout(timer);
}
},100);
/*But if, due to some reasons, the 'someCondition' never gets true than you need to
clear the timer otherwise it might turn into an infinite loop*/
setTimeout("clearTimeout(timer)",10000) //10 seconds or more
 
 

Comments