I am working on the snippet below. Is there a way to check whether the setInterval()
is really killed or still running in background processing?
Technically what I need to do is killing the JS setInterval whenever the .map
is not in the page. My understanding is the setInterval()
still running every 2 second just is not writing on the console because of if
statement.
setInterval(
function() {
if ($(".map")[0]) {
console.log("Map is in the Page");
} else {
//Stop Interval
}
}, 2000);
setTimeout(function(){ $(".box").empty();
}, 9000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
<div class="map">Map in Here</div>
</div>