jQuery setInterval and setTimeout

[javascript]
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
[/javascript]

Leave a Reply