PDA

View Full Version : Background color



mbzbugsy
01-25-2006, 11:13 AM
Hi, this code works only with ie, can anyone make it work with other browsers as well?.

<SCRIPT language="JavaScript">
<!--
function bcolor(bcol,d_name)
{
if (document.all)
{
var thestyle= eval ('document.all.'+d_name+'.style');
thestyle.backgroundColor=bcol;
}
}
//-->
</SCRIPT>


<TABLE width="200" border="1" cellspacing="0" cellpadding="0">
<TR>
<TD ID="td1" style="width:50%; background-color:lightblue"
onMouseover="bcolor('yellow','td1');"
onMouseout="bcolor('lightblue','td1');">
This goes to Yellow
</TD>
<TD ID="td2" style="width:50%; background-color:lightblue"
onMouseover="bcolor('red','td2');"
onMouseout="bcolor('lightblue','td2');">
This goes to Red
</TD>
</TR>
</TABLE>

Thanks for reading!

Twey
01-25-2006, 04:56 PM
<script type="text/javascript">
function bcolor(bcol,d_name) {
if (typeof document.getElementById == "function") {
var i, el = new Array();
if(!(el[0] = document.getElementById(d_name))) {
el = document.getElementsByName(d_name);
}
for(i=0;i<el.length;i++) el[i].style.backgroundColor = bcol;
}
}
</script>