What I’m trying to do is play and pause a function ie press a button to start a function press a button to pause so on. I am not entirely sure how this can be done I have tried .live() and .die() but they don’t work.
I have the HTML below
<button class="play">play</button>
<button class="pause">pause</button>
<div class="divafter"></div>
and the jQuery which I’m not entirely sure what .die() does but on the jsfiddle seems to speed up the interval time.
(function($){
playing = function() {
window.setInterval(function() {
$(".divafter").after("playing <br/>");
}, 500);
};
})(jQuery);
$(".play").click(function(){
playing().live();
});
$(".pause").click(function(){
playing().die();
});
Try this jsFiddle example. You need to use clearInterval() to stop setInterval().
jQuery: