function on_cell(direction, that) {
var tag = direction == 'column' ? 'td'
: 'tr'
;
var alltags = document.getElementsByTagName(tag);
for(var i = 0; i < alltags.length; i++) {
if(direction == 'column' && alltags.item(i).className == that.className) {
alltags.item(i).style.backgroundColor = 'rgb(240, 240, 200)';
}
else if(direction == 'row' && alltags.item(i).className == that.className) {
alltags.item(i).style.backgroundColor = 'rgb(240, 240, 200)';
}
}
}
function out_cell(direction, that) {
var tag = direction == 'column' ? 'td'
: 'tr'
;
var alltags = document.getElementsByTagName(tag);
for(var i = 0; i < alltags.length; i++) {
if(direction == 'column' && alltags.item(i).className == that.className) {
alltags.item(i).style.backgroundColor = '';
}
else if(direction == 'row' && alltags.item(i).className == that.className) {
alltags.item(i).style.backgroundColor = '';
}
}
}
<table>
<tr>
<th class="col_1" onmouseover="on_cell('column', this);" onmouseout="out_cell('column', this);">Rubrik</th>
<th class="col_2" onmouseover="on_cell('column', this);" onmouseout="out_cell('column', this);">Rubrik</th>
<th class="col_3" onmouseover="on_cell('column', this);" onmouseout="out_cell('column', this);">Rubrik</th>
</tr>
<tr class="row_1" onmouseover="on_cell('row', this);" onmouseout="out_cell('row', this);">
<td class="col_1">Test</td>
<td class="col_2">Test</td>
<td class="col_3">Test</td>
</tr>
<tr class="row_2" onmouseover="on_cell('row', this);" onmouseout="out_cell('row', this);">
<td class="col_1">Test</td>
<td class="col_2">Test</td>
<td class="col_3">Test</td>
</tr>
<tr class="row_3" onmouseover="on_cell('row', this);" onmouseout="out_cell('row', this);">
<td class="col_1">Test</td>
<td class="col_2">Test</td>
<td class="col_3">Test</td>
</tr>
</table>
Går ju naturligtvis att göra snyggare t.ex. genom att ge td-arna klasser i stället för att sätta attribut direkt.
