Skip to content
Loading
  
  •   
  • #timer {  
  •   font-size:150px;  
  •   margin:0 auto;  
  •   width:1000px;  
  • }  
  •   
  • #controls {  
  •   margin:0 auto;  
  •   width:600px;      
  • }  
  •   
  • #controls button {  
  •   font-size:24px;  
  • }  
  •   
  •   
  • var hours =0;  
  • var mins =0;  
  • var seconds =0;  
  •   
  • $('#start').click(function(){  
  •       startTimer();  
  • });  
  •   
  • $('#stop').click(function(){  
  •       clearTimeout(timex);  
  • });  
  •   
  • $('#reset').click(function(){  
  •       hours =0;      mins =0;      seconds =0;  
  •   $('#hours','#mins').html('00:');  
  •   $('#seconds').html('00');  
  • });  
  •   
  • function startTimer(){  
  •   timex = setTimeout(function(){  
  •       seconds++;  
  •     if(seconds >59){seconds=0;mins++;  
  •        if(mins>59) {  
  •        mins=0;hours++;  
  •          if(hours <10) {$("#hours").text('0'+hours+':')} else $("#hours").text(hours+':');  
  •                        }  
  •                          
  •     if(mins<10){                       
  •       $("#mins").text('0'+mins+':');}         
  •        else $("#mins").text(mins+':');  
  •                    }      
  •     if(seconds <10) {  
  •       $("#seconds").text('0'+seconds);} else {  
  •       $("#seconds").text(seconds);  
  •       }  
  •        
  •       
  •       startTimer();  
  •   },1000);  
  • }  
  •       
  •    
  •  It will create a Timer (Stop Watch) and all your doubts related to timer will be resolved.
     
     
    0
  • Mageshwaran R
    0
    Hi KarthikRaja,
     Please try this code:
    1.   
     
    0
  • Ashutosh Gupta
    0
    use settimeout, setinterval inbuilt function.
    0