var divs = document.getElementsByTagName("DIV"); for (var i = 0; i < divs.length; i++) { divs[i].onmouseover = function () { this.className = "onmouseover"; }; divs[i].onmouseout = function () { this.className = "onmouseout"; }; }