var box = document.getElementsByClassName('box'); for(var i=0; i<box.length; i++) box[i].onmouseover = function() { alert('here'); }