How to stop setinterval() after sometimes in jquery?

By Hardik Savani | October 1, 2016 | Category : Javascript jQuery

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:


<!DOCTYPE html>



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

<script type="text/javascript" src="//"></script>



<button>Click to Start</button>


<script type="text/javascript">

$(document).ready(function() {



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

var countTime = 0;

var storeTimeInterval = setInterval(function(){


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

if(countTime == 12){




}, 5000);






Maybe it can help you...

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: