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