I need to implement a timer in my game. how can i do it? I want to do it using dom and jquery if possible.can someone help?

Recommended Answers

window.setInterval(yourfunctionhere, 10000);

function yourfunctionhere() { #do something }
Jump to Post

did it help?

Jump to Post

All 6 Replies

window.setInterval(yourfunctionhere, 10000);

function yourfunctionhere() { #do something }
commented: spot on +5

did it help?

not really :(

Here is a simple JavaScript timer that you can adapt.

<!DOCTYPE html>
<div id="myTimer"></p>
var sec = 5;
var myTimer = document.getElementById('myTimer');
window.onload = countDown;

function countDown() {
        myTimer.innerHTML = sec;        
        if (sec <= 0) {return;}
        sec -= 1;
        window.setTimeout("countDown()", 1000);


Hi techyworld,

Hope this helps:

var intervalID;
var gameTimer;
// 1000 mS equivalent to 1 second
var timeInterval = 1000;

gameTimer = function(){
    /** ... do anything here ... **/
    /** set which should be update etc. **/

intervalID = setInterval(gameTimer,timeInterval);

/** in case you need to remove the interval function **/

Here's a very simple JS fiddle example too: Online Sample (JSFIDDLE)

Here is an updated version of what I previously posted. This example can be adapted in a web site that shows a count down timer prior to letting you proceed, submit, download, etc...


In the example, the button is disabled until the counter reaches 00 seconds.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.