var elems = document.getElementsByTagName('img'); for( i = 0; i < elems.length; i++){ for(z=1;z<=100;z++) { namme="name"+z; if(elems[i].name==namme) elems[i].src='clear.png'; } }