<!DOCTYPE html>
<html>
<head>
<style>
td {width:50px; height:30px;border:1px solid;}
</style>
</head>
<body>
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
<script>
[...document.getElementsByTagName("td")].forEach(el => {
el.addEventListener("mouseenter", setColor);
el.addEventListener("mouseleave", removeColor);
});
function setColor() {
this.style.backgroundColor="rgb("+Math.floor(Math.random()*256)+", "+Math.floor(Math.random()*256)+", "+Math.floor(Math.random()*256)+")";
}
function removeColor() {
this.style.backgroundColor="inherit";
}
</script>
Comentarios sobre la versión: 1 (1)