i have a loop with setTiemout inside and i need stop it via onClick button
var loop = function(){
for (var i = 0; i < tx.length; i++) {
setTimeout((function(x) {
return function() {
$("#div").append(tx[x] + " <br />");
};
})(i), 500 * i);
}
};
$("#start").on("click", loop);
$("#stop").on("click", stop);
i have the example in JSFiddle start|stop loop with buttons
Thank's
See Question&Answers more detail:os