While The above solution was being worked out, I came up with this, which works as well and seems a bit simpler. I did think about using event listeners but, it seemed more than necessary for this application:
Code:
<html>
<head>
<title>Table Clickover - Demo</title>
<script type="text/javascript">
function toggleCells(el, col1, col2){
for (i = 0; i < el.parentNode.childNodes.length; i++)
if (el.parentNode.childNodes[i].tagName)
el.parentNode.childNodes[i].style.backgroundColor=col2
el.style.backgroundColor=col1
}
</script>
</head>
<body>
<table>
<tr>
<td style="background-color:white;" onclick="toggleCells(this, 'red', 'white')"> </td><td style="background-color:white;" onclick="toggleCells(this, 'red', 'white')"> </td><td style="background-color:white;" onclick="toggleCells(this, 'red', 'white')"> </td>
</tr>
<tr>
<td style="background-color:blue;" onclick="toggleCells(this, 'orange', 'blue')"> </td><td style="background-color:blue;" onclick="toggleCells(this, 'orange', 'blue')"> </td><td style="background-color:blue;" onclick="toggleCells(this, 'orange', 'blue')"> </td>
</tr>
<tr>
<td style="background-color:pink;" onclick="toggleCells(this, 'green', 'pink')"> </td><td style="background-color:pink;" onclick="toggleCells(this, 'green', 'pink')"> </td><td style="background-color:pink;" onclick="toggleCells(this, 'green', 'pink')"> </td>
</tr>
</table>
</body>
</html>
Bookmarks