Click to See Complete Forum and Search --> : Td bgcolor


scialom
06-24-2003, 10:16 AM
Hi,

How do I change the bgcolor of a td?

I try this:
function bgChange(_w){

document.all[_w].style.bgcolor='brown';
}

....
<td id="1" onmouseover="bgChange(1)">...</td>

Anyway it is not working. why?

Thanks
Assaf

requestcode
06-24-2003, 11:10 AM
Here is an example that I put togehter for someone else:
<html>
<head>
<title>Table Cell Color Change</title>
<script language="JavaScript">
function chgtabcolor(name,bcolor,txt)
{
if(document.getElementById)
{
elm=document.getElementById(name.id)
elm.style.backgroundColor=bcolor
var newText = document.createTextNode(txt)
elm.replaceChild(newText, elm.childNodes[0])
}
}
</script>
</head>
<body>
<table align="center" border="1" width="200" height="120" cellspacing="0" cellpadding="0">
<tr>
<td id="cell1" align="center" valign="middle" width="66" height="20" onmouseover="chgtabcolor(this,'lightgreen','World')" onmouseout="chgtabcolor(this,'white','Hello')"> Hello </td>
<td id="cell2" align="center" valign="middle" width="66" height="20" onmouseover="chgtabcolor(this,'red','World')" onmouseout="chgtabcolor(this,'white','Hello')"> Hello </td>
<td id="cell3" align="center" valign="middle" width="66" height="20" onmouseover="chgtabcolor(this,'yellow','World')" onmouseout="chgtabcolor(this,'white','Hello')">Hello</td>
</tr>
<tr>
<td id="cell4" align="center" valign="middle" width="66" height="20" onmouseover="chgtabcolor(this,'lightgreen','World')" onmouseout="chgtabcolor(this,'white','Hello')"> Hello </td>
<td id="cell5" align="center" valign="middle" width="66" height="20" onmouseover="chgtabcolor(this,'red','World')" onmouseout="chgtabcolor(this,'white','Hello')"> Hello </td>
<td id="cell6" align="center" valign="middle" width="66" height="20" onmouseover="chgtabcolor(this,'yellow','World')" onmouseout="chgtabcolor(this,'white','Hello')">Hello</td>
</tr>
</table>
</body>
</html>