xxxxxxxxxx
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p id="seconds-counter"></p>
</body>
</html>
<script>
var seconds = 0;
var el = document.getElementById('seconds-counter');
function incrementSeconds() {
seconds += 1;
if(seconds == 10){
myStop();
}
el.innerText = "You have been here for " + seconds + " seconds.";
}
var cancel = setInterval(incrementSeconds, 1000);
function myStop() {
clearInterval(cancel);
}
</script>
xxxxxxxxxx
// Store the interval ID
const intervalId = setInterval(() => {
// Some code to execute repeatedly
console.log("Interval is running...");
}, 1000);
// Clear the interval after 5 seconds
setTimeout(() => {
clearInterval(intervalId);
console.log("Interval cleared.");
}, 5000);
xxxxxxxxxx
// interval id initialization
var myIntervalID;
// setInterval execution
myIntervalID = setInterval(function() {
// your main code for interval execution (this is just an example code)
$("body").css("font-size", '75px').addClass("interval-deletion-signal");
// setInterval deletion
if($("body").hasClass("interval-deletion-signal")){
console.log('please make it stop the interval');
clearInterval(myIntervalID);
}
}, 1);
xxxxxxxxxx
var i = setInterval(FunctionA ,1000);
setTimeout(function( ) { clearInterval( i ); }, 5000);
xxxxxxxxxx
$timer = setInterval(command, 5000);
clearInterval($timer);
//if you find the answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)