Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  Every <input type="text" id="timer"></input>Seconds<br>
  <button class="start">Start</button>
<h1>0</h1>
<button class="play">Play</button>
<button class="pause">Pause</button>
  
</body>
</html>
 
var interval = null;
var time = 0;
var output = $('h1');
function setTimer() {
  var seconds = +($("#timer").val());
  
  interval = setInterval(function() {
        time++;
        output.text( time );
   }, seconds*1000);
}
//with jquery
$('.pause').on('click', function(e) {
  e.preventDefault();
  if(interval){
    clearInterval(interval);
  }
});
$('.play').on('click', function(e) {
  e.preventDefault();
  setTimer();
});
$('.start').click(function(){
  time = 0;
  setTimer();
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers