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();});