I want to trigger a setInterval()
based on a success of a particular function.
function myCountComplete(){
//do something
count++;
if(count > 10){
var myVar = setInterval(function(){ setColor() }, 300);
}
}
function setColor() {
var x = document.body;
x.style.backgroundColor = x.style.backgroundColor == "yellow" ? "pink" : "yellow";
}
How can I clear the myVar
interval when a button is clicked?
$("#stop").click(function(){
clearInterval(myVar);
});