How to stop a jQuery script
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/914951/show-and-hide-divs-at-a-specific-time-interval-using-jquery">Show and hide divs at a specific time interval using jQuery</a>  </p>
</blockquote>



<p>I have a jQuery script what is showing and hiding divs at a specific interval. It's working fine but I have one problem, its showing and hiding divs round and round so basically its never stops.
How can I make this stop? Lets say it stops after showing 3x the divs.</p>

<pre><code>$(function() {
    var timer = setInterval( showDiv, 5000);    
    var counter = 0;

    function showDiv() {
        if (counter == 0) { 
            counter++; 
            return; 
        }

        $('div','#container')
            .stop()
            .hide()
            .filter( function() { return this.id.match('div' + counter); })   
            .show('fast');

        counter == 3? counter = 0 : counter++; 
    }
});
</code></pre>
