JQuery to achieve table interlacing color change and mouse over the two methods of color change


One, alternate color


$("tr:odd").css("background-color","#eeeeee");
$("tr:even").css("background-color","#ffffff");

Or one line:


$("table tr:nth-child(odd)").css("background-color","#eeeeee");

: NTH -child matches the NTH child or even element under its parent element

Two, 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 simultaneously or separately.