1. Change colors on alternate lines
$("tr:odd" ).css("background-color","#eeeeee");
$("tr:even").css("background-color","#ffffff");
Or do it in one line:
$("table tr:nth -child(odd)").css("background-color","#eeeeee");
:nth-child matches the Nth child or odd-even element under its parent element
2. The mouse changes color
$("tr ").live({
mouseover:function(){
$(this).css("background-color","#eeeeee");
},
mouseout:function() {
$(this).css("background-color","#ffffff");
}
})
or
$("tr").bind("mouseover",function(){
$(this).css("background-color","#eeeeee");
})
$("tr").bind("mouseout",function(){
$(this ).css("background-color","#ffffff");
})
Of course, both live() and bind() can bind multiple events at the same time or separately.