A little bit generic solution:
Let's say I want to have a simple way to make tables with rows that will highlight when I put mouse pointer over them. In ideal world this would be very easy, with just one simple CSS rule:
tr:hover { background: red; }
Unfortunately, older versions of IE don't support :hover selector on elements other than A. So we have to use JavaScript.
In that case, I will define a table class "highlightable" to mark tables that should have hoverable rows. I will make the background switching by adding and removing the class "highlight" on the table row.
CSS
table.highlightable tr.highlight { background: red; }
JavaScript (using Prototype)
// when document loads
document.observe( 'dom:loaded', function() {
// find all rows in highlightable table
$$( 'table.highlightable tr' ).each( function( row ) {
// add/remove class "highlight" when mouse enters/leaves
row.observe( 'mouseover', function( evt ) { evt.element().addClassName( 'highlight' ) } );
row.observe( 'mouseout', function( evt ) { evt.element().removeClassName( 'highlight' ) } );
} );
} )
HTML
All you have to do now is to add class "highlightable" to any table you want:
<table class="highlightable">
...
</table>