for (var menu,ctr = 0; ctr < menus.length; ctr++) { menu = document.getElementById('menu-' + menus[ctr]); if(menu != null) { menu.onmouseover = function() { this.className = 'over' } menu.onmouseout = function() { this.className = '' } } }