Quantcast
Channel: User Ja͢ck - Stack Overflow
Viewing all articles
Browse latest Browse all 44

Answer by Ja͢ck for javascript: stop setInterval after element removal

$
0
0

Have you tried storing the intervalId on the #element itself using $.data?

$('#element').mouseover(function() {     var $this = $(this);     $.post('ajax/ajax.php', function(data) {         $('<div id="tooltip"></div>').appendTo("div#main");         $('#tooltip').html(data);         $('#tooltip').show();         // save interval id here         var intervalId = setInterval('pics_load', 3000);         $this.data('intervalId', intervalId);     });}).mouseout(function(){     // retrieve intervalId here     var intervalId = $(this).data('intervalId');     clearInterval(intervalId);     $('#tooltip').empty();     $('#tooltip').remove();});

Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>