setTimeout() and setInterval in jQuery

setTimeout() and setInterval in jQuery

Today we will discuss about setTimeout() and setInterval function in jQuery .

setTimeout function :-

The setTimeout() is executed only once.
Use the clearTimeout() method to prevent the function from starting.
By calling clearTimeout() you can to stop the execution.

var myTimeout = setTimeout(function () {
		// Your logic
}, 2500); // 2500 are milliseconds  

// to clear

setInterval function :-

The setInterval() method calls a function at specified intervals (in milliseconds).
The setInterval() method continues calling the function until clearInterval() is called.
The setInterval function returns an interval id to be used in the case you want to stop the

 var count = 0;
    var intervalId = setInterval(function(){        
        // your logic
        if(count ==5){
        	console.log('Stop function');
        	clearInterval(intervalId);  // stop after count euqal 5
    }, 500);

setTimeout() and setInterval in jQuery

Related Post Create A Pie Chart Using JavaScript.

Like us on Facebook and Linkedin for more updates.

Leave a Reply

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

Back To Top