Click to See Complete Forum and Search --> : MouseOver effect


Alka
09-19-2003, 02:28 AM
hello,
I am having a problem in Mouseover effect of <TR>. I want that when I place my mouse on/out of <TR> the background color of the <TR> should chnge. The real problem is that I am retrieving all data from database and generating <TR> without an object name.

pyro
09-19-2003, 07:57 AM
You could try something like this. This will go through all <td>'s in the first table on the page and set their onmouseover/onmouesout background colors:

<style type="text/css">
table tr td {
border: 1px solid;
}
</style>
<script type="text/javascript">
function setRollover() {
table = document.getElementsByTagName("table")[0];
td = table.getElementsByTagName("td");
for (i in td) {
td[i].onmouseover = function() { this.style.backgroundColor = '#eeeeee' };
td[i].onmouseout = function() { this.style.backgroundColor = 'transparent' };
}
}
onload = setRollover;
</script>
</head>
<body>
<table>
<tr>
<td>Row One, Cell One</td>
<td>Row One, Cell Two</td>
</tr>
<tr>
<td>Row Two, Cell One</td>
<td>Row Two, Cell Two</td>
</tr>
</table>