var image = ["1","2"],el=document.getElementById("id_elementa"); function rotator(){ el.src = image[~~(0.5+Math.random())]+".jpg"; }