I wonder if it actually is possible to stop function explicitly, after using setInterval on it.
<script>
setInterval(function(){document.write("Hello");},1000);
</script>
I wonder if it actually is possible to stop function explicitly, after using setInterval on it.
<script>
setInterval(function(){document.write("Hello");},1000);
</script>
Use clearInterval()
:
var timer = setInterval(function(){
document.write("Hello");
if (someCondition) {
clearInterval(timer); // this stops the interval
}
},1000);