<style>
td, table {
border: solid 1px;
cursor: pointer;
color: navy;
}
tr {
background: lightgrey;
}
</style>
<table>
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td>21</td>
<td>22</td>
<td>23</td>
</tr>
<tr>
<td>31</td>
<td>32</td>
<td>33</td>
</tr>
</table>
<script>
window.onload = function () {
var table = document.body.children[0];
table.onmouseover = function (e) {
e = e || event;
var target = e.target || e.toElement;
if (target.tagName == 'TD') {
target.parentNode.style.background = 'lightgreen';
}
}
table.onmouseout = function (e) {
e = e || event;
var target = e.target || e.fromElement;
if (target.tagName == 'TD') {
target.parentNode.style.background = 'lightgrey';
}
}
table.onclick = function (e) {
e = e || event;
var target = e.target || e.srcElement;
if (target.tagName == 'TD') {
alert(target.innerHTML)
}
}
}
</script>