aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery setInterval() Function Example in JavaScript

Feb 25, 2013

Here I will explain how to use jQuery setInterval function with example. jQuery setInterval function is used to execute functions at regular intervals of time. Suppose if we want to execute one JavaScript function for every 10 seconds or for a specific time we can use jQuery setInterval function to achieve this functionality. 

In previous articles I explained Start and Stop timer in JavaScript, Show user current location on google map, Regular expression to validate file upload extension,
jQuery Bouncing Menu Example and many articles relating to jQuery, JavaScript. Now I will explain how to use jQuery setInterval() function with example. 

We can use setInterval function in different ways like as shown below

Method 1:

setInterval(yourfunction(), timeinterval);

function yourfunction() {
// your code here
Method 2

setInterval(function(){// your code here
}, timeinterval);
For complete example check below code

<html xmlns="">
<title>jQuery setInterval function example</title>
<script type="text/javascript">
var count = 0;
function changeColor() {
// Call function with 500 milliseconds gap
setInterval(starttimer, 500);
function starttimer() {
count += 1;
var oElem = document.getElementById("divtxt"); = == "red" ? "blue" : "red";
document.getElementById("lbltxt").innerHTML = "Your Time Starts: " + count;
<div id="divtxt">
<label id="lbltxt"style="font:bold 24px verdana" />
<button onclick="changeColor();">Start Timer</button>
Live Demo

Click on below button to run timer function for specific intervals of time

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.