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.
setInterval(yourfunction(), timeinterval);
function yourfunction() {
// your code here
}
|
setInterval(function(){// your code here
}, timeinterval);
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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");
oElem.style.color = oElem.style.color == "red" ? "blue"
: "red";
document.getElementById("lbltxt").innerHTML = "Your Time Starts: " + count;
}
</script>
</head>
<body>
<div id="divtxt">
<label id="lbltxt"style="font:bold 24px
verdana" />
</div>
<button onclick="changeColor();">Start
Timer</button>
</body>
</html>
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
0 comments :