How to stop a loop in setInterval(function()?
I've this script that make change a class every 3 seconds. How do I stop the loop, so it will stop on the second class?
$(function() {
var $target = $("#wrap");
var classes = ['hide', 'show'];
var current = 0;
setInterval(function() {
$target.removeClass(classes[current]);
current = (current+1)%classes.length;
$target.addClass(classes[current]);
}, 3000); // 1500 ms loop
});