jQuery Quickie For Zebra Highlighting In Tables

If you haven’t taken the time to check out this framework you absolutely must do so now. jQuery allows you to accomplish so much more with so much little. It may be a little arcane to look at the first time, but after a little research, you’ll wonder how you lived without it. Case in point, here’s a quick script to add zebra highlighting to a table with id ‘myTable’.

// Do zebra highlighting $(“#myTableID tr:even”).addClass(‘altrow’);

This code can be added to an existing page and automagically apply the styles necessary. (You’ll still have to define the style in your css)

While you can do something similar using just CSS using the :even pseudoselector, it is not as universally supported. And jQuery will allow you to do far more than simply alternate table colors.