$("#products tbody > tr").filter(":even").css({"background" : "#ddd"}).addClass("even"); $("#products tbody > tr").hover(function() { $(this).css("background", "#C1DAD6"); }, function() { oldBgColor = $(this).hasClass("even") ? "#ddd" : "#eee"; $(this).css("background", oldBgColor); });
<table id="products" bgcolor="#eee" cellspacing="3" cellpadding="5" width="100%" border="3" bordercolor="#fff"> <thead bgcolor="#aaa"> <th>Продукт</th> <th>Стоимость</th> </thead> <tbody> <tr> <td>Молоко</td> <td>48 руб.</td> </tr> <tr> <td>Сыр</td> <td>98 руб.</td> </tr> <tr> <td>Мясо</td> <td>260 руб.</td> </tr> <tr> <td>Макароны</td> <td>34 руб.</td> </tr> <tr> <td>Хлеб</td> <td>25 руб.</td> </tr> </tbody> </table>
#products { padding: 5px; font-family: "Tahoma"; font-size:10pt; } #products thead th { padding:5px; font-weight:bold; } #products tbody td { padding:5px; }