I've created a new div element using jQuery:
$(document.body).append('<div id="test"></div>');
Then, I display a success message and remove the div after 10 seconds:
$('test').html('SUCCESS!');
setTimeout(function(){
$('#test').remove();
}, 10000);
After that, I check if the div removal is complete and log a message to the console:
$(window).on('scroll', function () {
if($('#test').length === 0){
console.log('DIV removed!');
} else {
console.log('DIV not removed!!!')
}
}
Unfortunately, when I scroll up or down, the message "DIV not removed!!!" is displayed.
Can anyone explain why my div is not being removed?