JQuery - how to stop a function?
<p>I have this code</p>

<pre><code>&lt;script type="text/javascript"&gt; 
  function test(counter) {
      if(counter==4)
        {
              counter=0;
         }
      if(counter==0)
         {
            //various stuff

          }

          counter = counter + 1;
         setTimeout(function () { test(counter); }, 7000);
  }

 $(document).ready(function () {

 test(0);

 });
 &lt;/script&gt;
</code></pre>

<p>So when the page loads the <code>test(0)</code> function is running.</p>

<p>But i have this link <code>&lt;a onclick="test(1)" rel="2" href="#"&gt;</code> that calls the same function again, having as a result to have the same function running twice.</p>

<p>Is there a way to stop the function that is already running and then start the new one??</p>
