How to stop setinterval() after sometimes in jquery?

How to stop setinterval() after sometimes in jquery?

In this post we will give you information about How to stop setinterval() after sometimes in jquery?. Hear we will give you detail about How to stop setinterval() after sometimes in jquery?And how to use it also give you demo for it if it is necessary.

Sometimes we require to stop setInterval() after a while few time, so today i am going to give you simple example with setinterval stops after a while.

In this example i used two function as listed bellow:

setInterval() : Call on specified intervals time.

clearInterval() : Stop set interval.

You can see bellow full example, how to stop setinterval after 1 minute, You can also check demo, how work this example:

index.html

Also see:Jquery Select2 – Select box with search example code

<!DOCTYPE html>

<html>

<head>

<title>Jquery setinterval stop after sometime</title>

<script type="text/javascript" src="//code.jquery.com/jquery-1.4.2.min.js"></script>

</head>

<body>


<button>Click to Start</button>

<pre></pre>


<script type="text/javascript">

$(document).ready(function() {

$("button").click(function(){


$(this).attr("disabled",true);

$("pre").append('Stop After 1min.<br/>');


var countTime = 0;

var storeTimeInterval = setInterval(function(){

++countTime;

$("pre").append(countTime*5 + 'sec.<br/>');

if(countTime == 12){

clearInterval(storeTimeInterval);

$("pre").append('stop');

}

}, 5000);

});

});

</script>


</body>

</html>

Maybe it can help you…

Hope this code and post will helped you for implement How to stop setinterval() after sometimes in jquery?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

8  +  1  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US