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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.