title: How do I clear this setInterval inside a function?
body: <p>Normally, I’d set the interval to a variable and then clear it like <code>var the_int = setInterval(); clearInterval(the_int);</code> but for my code to work I put it in an anonymous function:</p>
  
  <pre><code>function intervalTrigger() {
    setInterval(function() {
      if (timedCount &gt;= markers.length) {
        timedCount = 0;
      }
  
      google.maps.event.trigger(markers[timedCount], "click");
      timedCount++;
    }, 5000);
  };
  
  intervalTrigger();
  </code></pre>
  
  <p>How do I clear this? I gave it a shot and tried <code>var test = intervalTrigger(); clearInterval(test);</code> to be sure, but that didn’t work.</p>
  
  <p>Basically, I need this to stop triggering once my Google Map is clicked, e.g.</p>
  
  <pre><code>google.maps.event.addListener(map, "click", function() {
    //stop timer
  });
  </code></pre>