Below is the code I have written using window.setInterval
and window.clearInterval
.
The window.setInterval
function works fine, but when I attempt to call window.clearInterval
, I encounter an error stating that intervalId is not defined
.
Is there a way to resolve this issue?
.....................................................
<div onclick="start_setinterval('1')">START</div>
<div onclick="start_setinterval('0')">STOP</div>
<script>
function start_setinterval(status) {
var xxx = setInterval(function() {
if (status == 1) {
do_start_setinterval();
} else {
clearInterval(xxx);
}
}, 5000);
}
function do_start_setinterval() {
alert("test");
}
</script>