loop pause resume jquery
by irwan dwiyanto
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<button id='pause'>Resume</button>
<button id='resume'>pause</button>
<br>
<div id='content'></div>
JavaScript
var timer = setInterval(function(){$("#content").append("Hello world</br>")},1000);
var pause = false;
$("#pause").click(function (){
if (pause){
timer = setInterval(function(){$("#content").append("Hello world</br>")},1000);
pause = false;
}
});
$("#resume").click(function(){
if (!pause){
pause = true;
clearInterval(timer);
}
});