title: stop settimeout in recursive function
body: <p>my problem is that I can not stop a timer. </p>
  
  <p>I had <a href="https://stackoverflow.com/questions/700048/jquery-constantly-ping-for-ajax-responce">this method</a>  to set a timeout from this forum.
  It supposed to store the identifyer in the global variable.
  By accident, I found out that it is still running after I hide "mydiv".</p>
  
  <p>I also need to know now, if the recursive function creates multiple instances or just one for the timeouts. Because first I thought that it overwrites "var mytimer" everytime.
  Now I am not so sure.</p>
  
  <p>What would be a solid way to stop the timer??</p>
  
  <pre><code>var updatetimer= function () {
  //do stuff
          setTimeout(function (){updatetimer();}, 10000);
  
  }//end function
  
  
  //this should start and stop the timer
  $("#mybutton").click(function(e) { 
           e.preventDefault();
           if($('#mydiv').is(':visible')){
                     $('#mydiv').fadeOut('normal');
               clearTimeout(updatetimer);
  
          }else{
                     $('#mydiv').fadeIn('normal');
                     updatetimer();
                 }
  });
  </code></pre>
  
  <p>thanks, Richard</p>