Ecco il codice corretto.
Codice PHP:
<script type="text/javascript">
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;
row = tr.index()+1;
$('table tr').each(function() {
$thisTR = $(this)
var xrow = $thisTR.index() + 1;
if (xrow <= row) {
$($thisTR).find('td').each(function() {
$thisTD = $(this);
var xcol = $thisTD.index() + 1;
if ((xcol <= col && xrow == row) || (xcol == col && xrow != row)) {
$thisTD.addClass('tdhovered');
}
});
}
});
}
});
table.bind('mouseout', function() {
$('td', table).removeClass('tdhovered');
$('tr', table).removeClass('trhovered');
});
};
$(document).ready(function() {
foobar('table');
});
</script>