I want to execute a function clearIntervalautomatically after deleting the div containing the function setInterval, and this div is the result of the ajax response because it does not stop after the div is deleted.
$('#element').mouseover(function(){
$.post('ajax/ajax.php', function(data) {
$('<div id="tooltip'></div>").appendTo("div
$('#tooltip').html(data);
$('#tooltip').show();
});
}).mouseout(function(){
clearInterval(intervalId);
$('#tooltip').empty();
$('#tooltip').remove();
});
The ajax response datacontains a javascript function setIntervalwith an Id interval handler:
var intervalId = window.setInterval(pics_load, 3000);
I tried using jquery unload , but the same problem:
$('#tooltip').unload(function(){
clearInterval(intervalId);
}
I tried using it inside ajax response:
$(window).unload(function(){
clearInterval(intervalId);
}
source
share