(function(){ var i=0; var seti1 = setInterval(function(){ var elem=document.getElemetnById("id_"+i%3+'1') elem.style.left = (parseInt(elem.style.left)+10)+"px"; if(parseInt(elem.style.left) > 100&&i==2) clearInterval(seti1); i++; },33); }())