Striping Tables

If your site has a lot of tabular data, you should add stripes to your tables—without them, the information can be difficult to read and understand. Unfortunately, there’s still no way to use CSS to stripe table rows that works in all commonly used browsers. It used to be the case that using JavaScript to stripe table rows was so difficult that most people didn’t bother. With jQuery, it’s nice and simple as seen in Figure 16.7.

Figure 16.7. This list of albums, with its alternating stripes, is easy to read.

To create zebra-striped tables:

1.
$("tr").mouseover(function() {
  $(this).addClass("over");
});
Script 16.8 (our HTML ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.