function twinkle(){ let count = 0; (function bb(){ setTimeout(function(){ $("#mapdots .twinkle").removeClass("active"); if(count==3){ count=0; } $($("#mapdots .twinkle")[count]).addClass("active"); count++; bb(); },1500); })();