<div id="timer">0</div> <input type="button" id="bttn" value="confirm"> <script> var timer = 0, div = document.getElementById("timer"); setInterval(function(){ div.innerHTML = ++timer; }, 1000); document.getElementById("bttn").onclick = function(){ var time = new Date; confirm("..."); timer += Math.round( ( new Date - time ) / 1000 ); div.innerHTML = timer; }; </script>