title: javascript: stop setInterval after element removal
body: <p>I want to execute <code>clearInterval</code> function automatically after removing div which containing <code>setInterval</code> function and this div is the result of ajax response because it don't stop itself after removing the div.</p>
  
  <pre><code>$('#element').mouseover(function(){
       $.post('ajax/ajax.php', function(data) {
           $('&lt;div id="tooltip'&gt;&lt;/div&gt;").appendTo("div#main");
           $('#tooltip').html(data);
           $('#tooltip').show();
       });
  }).mouseout(function(){
       clearInterval(intervalId);
       $('#tooltip').empty();
       $('#tooltip').remove();
  });
  </code></pre>
  
  <p>The ajax response <code>data</code> is containing javascript <code>setInterval</code> function with interval Id handler:</p>
  
  <pre><code>var intervalId = window.setInterval(pics_load, 3000);
  </code></pre>
  
  <p>I tried to use <a href="http://api.jquery.com/unload/" rel="nofollow">Jquery unload</a> but the same problem:</p>
  
  <pre><code>$('#tooltip').unload(function(){
       clearInterval(intervalId);
  }
  </code></pre>
  
  <p>I tried also to use it inside the ajax response:</p>
  
  <pre><code>$(window).unload(function(){
       clearInterval(intervalId);
  }
  </code></pre>