title: jQuery repeated event till user clicks on it
body: <p>I have an animation on a partially hidden div container that will execute when the result returned from an ajax query is true. (The animation actually just brings the box into larger view, and then sliding it back in again)</p>
  
  <pre><code>$('#box').animate({'right':'-184px'}, 300, 'easeOutBounce');
  $('#box').animate({'right':'-194px'}, 150, 'easeOutExpo');
  </code></pre>
  
  <p>How can I make this animation repeat every 4 seconds until the user clicks on <code>$('#box')</code>?</p>
  
  <p>Any help is greatly appreciated. Thanks :)</p>
  
  <p>Based on jAndy's and rahul's code..this is how I'm thinking of implementing it (fictitious setting).</p>
  
  <p>This is the code that starts the animation:</p>
  
  <pre><code>// declares the variable first or $('#stop').click() will return undefined variable
  var intervalId = '';
  $('#submit').submit(function () {
    var intervalId = setInterval(function(){
      $('#box').animate({'right':'-184px'}, 300, 'easeOutBounce');
      $('#box').animate({'right':'-194px'}, 150, 'easeOutExpo');
    }, 4000);
  });
  </code></pre>
  
  <p>This is the code that will supposedly will stop the animation:</p>
  
  <pre><code>$('#stop').click(function () {
    clearInterval(intervalId);
  });
  </code></pre>