Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

javascript count up timer

var minutesLabel = document.getElementById("minutes");
var secondsLabel = document.getElementById("seconds");
var totalSeconds = 0;
setInterval(setTime, 1000);

function setTime() {
  ++totalSeconds;
  secondsLabel.innerHTML = pad(totalSeconds % 60);
  minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
}

function pad(val) {
  var valString = val + "";
  if (valString.length < 2) {
    return "0" + valString;
  } else {
    return valString;
  }
}
<label id="minutes">00</lable>:<label id="seconds">00</label>
 
PREVIOUS NEXT
Tagged: #javascript #count #timer
ADD COMMENT
Topic
Name
7+8 =