var allCells = []; for (i=0;i<5;i++) { var elem = document.getElementById("a0"+i); allCells.push(elem); } allCells[2].style.visibility = 'hidden'; allCells[3].style.visibility = 'hidden';