copia e incolla questo esempio (fatto al volo)
codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xhtml 1.0</title>
<style type="text/css">
td {
border : 1px solid #767676;
width : 80px;
height : 50px;
}
.trhovered td,
td.tdhovered {
background : #e1e1e5;
cursor : pointer;
}
</style>
<script type="text/javascript" src="jquery-1.4.2.min.js"> </script>
</head>
<body>
<table>
<tbody>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
<tr>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
<td>&nb sp;</td>
</tr>
</tbody>
<table>
</body>
</html>
<script type="text/javascript">
// <![CDATA[
function foobar(el) {
/* event delegation */
var table = $(el);
var tbody = $('tbody', table);
table.bind('mouseover', function(event) {
var el = event.target;
if (el.nodeName === 'TD') {
var td = $(el);
var tr = td.parent();
col = tr.children().index(td) + 1;
$(['td:nth-child(', col, ')'].join(''), tbody).addClass('tdhovered');
$(tr, tbody).addClass('trhovered');
}
});
table.bind('mouseout', function() {
$('td', table).removeClass('tdhovered');
$('tr', table).removeClass('trhovered');
});
};
$(document).ready(function() {
foobar('table');
});
// ]]>
</script>
questo utilizza l'event delegation sulla tabella e sfrutta il selettore nth-child per individuare la colonna