see here http://jsfiddle.net/Ksb2W/5/
$(function(){
$('table tr td').click(function () {
var selected = $(this).parent();
var index = selected.GetIndex();
var parentOfRow = $(selected.parent()[0].tagName);
$(".selectedRow",parentOfRow).removeClass("selectedRow");
parentOfRow.each(function(){
$("tr:eq("+index +")",this).addClass("selectedRow");
});
});
$("tr").hover(function(){
var row = $(this).GetIndex();
$(".table").each(function(){
$("tr:eq("+row+")",this).addClass("hoverx");
});
},function(){
var row = $(this).parent().children().index($(this));
$(".table").each(function(){
$("tr:eq("+row+")",this).removeClass("hoverx");
});
});
});
jQuery.fn.GetIndex = function(){
return $(this).parent().children().index($(this));
}
source
share