var zebraTables = Class.create(); zebraTables.prototype = { triggerClass: "hoverRows", tables: Object, /** INITIALIZE FUNCTION **/ initialize: function () { this.tables = document.getElementsByClassName(this.triggerClass); this.tables.each(function(item, index) { rows = item.getElementsByTagName('tr'); this.applyRowsHover(rows); }.bind(this)); }, /** FUNCTION WALKS OVER THE TABLE ROWS **/ applyRowsHover: function(rows) { tableRows = $A(rows); tableRows.each(function(row, index){ Event.observe(row, 'mouseover', function() { this.addClassName('over'); }, false); Event.observe(row, 'mouseout' , function() { this.removeClassName('over'); }, false); }.bind(this)); } } Event.observe(window, 'load', function() { var zebraTable = new zebraTables(); zebraTable.initialize; }, false);