var divs = new Array(); var i = 0; while(document.getElementById('food_div' + i)) { divs[i] = document.getElementById('food_div' + i) }