Pause and continue using setInterval
what I want to achieve when you click this href <a href="javascript:void(0)" class="pauser">pause/continue</a> , the timer pauses and continues its repeated click.
<script> $(document).ready(function () { var counter = 10; var id = setInterval(function() { counter--; if(counter > 0) { var msg = 'You can continue ' + counter + ' seconds'; $('#notice').text(msg); } else { $('#notice').hide(); $('#download').show(); clearInterval(id); } }, 1000); }); </script> My jQuery related HTML is here if you need to.
<a href="http://myurl.com" id="download" class="button" style="display: none;font-size:30px;">Continue !!</a><p id="notice"> You can continue in 10 seconds</p> Ok, I just want your pause event to set a boolean and then check that the boolean before you decrease the counter:
<a href="javascript:setPause();" class="pauser">pause/continue</a> and
var ispaused=false; function setPause(){ ispaused=!ispaused; } and
$(document).ready(function () { var counter = 10; var id = setInterval(function() { if(!ispaused){ ////the only new line I added from your example above counter--; if(counter > 0) { var msg = 'You can continue ' + counter + ' seconds'; $('#notice').text(msg); } else { $('#notice').hide(); $('#download').show(); clearInterval(id); } } }, 1000); }); That should do it, right?