Updated on Kisan Patel
Timer is a kind of event that automatically executes after specified number of mili-seconds.
Here is the example of a basic time in javascript:
<script language="javascript" type="text/javascript"> var count = 0; function TestFunction() { count++; document.getElementById("lblText").innerHTML = count; t = setTimeout("TestFunction()", 1000); } </script> <label id="lblText">0</label> <input type="button" id="btnTest" onclick="TestFunction()" value="Click me start timer" />
Here, TestFunction()
function executes after every 1 second and set the label value after incrementing. As the function is being called in setTimeout
method, it will keep executing indefinite number of times.
See the Pen RPdqzP by Kisan (@pka246) on CodePen.
Here is another example of timer in javascript:
See the Pen ZGPVBq by Kisan (@pka246) on CodePen.