Click to See Complete Forum and Search --> : change table cell background color


dryhat
12-14-2002, 09:26 AM
I am new here. I have been looking around for a script that would change the background color on table cells on a mouseover. This would be used in a nav bar. Thought this would be easy to find but so far no joy.
thanks

swon
12-14-2002, 09:32 AM
Hi,

use something like that (works not in Netscape 4)

<table>
<tr>
<td bgcolor="#AFAFAF"><a href="" onMouseOver="javascript:this.parentElement.bgColor='#0070C0'" onMouseout="javascript:this.parentElement.bgColor='#AFAFAF'">test</a></td>
</tr>
</table>


Swon

vickers_bits
12-15-2002, 07:26 AM
<script type="text/javascript" language="JavaScript"><!--
//obj is element name/id
//if color is empty string it will revert back to previous
function change_bg_color(obj, color){
if (document.layers) document.obj.bgColor=color;//nn4
else if (document.all) document.all[obj].style.backgroundColor=color;//ie4+
else if (document.getElementById) document.getElementById(obj).style.backgroundColor=color;//nn6+
};
//--></script>

<td onmouseover="change_bg_color(this, '#0F0F0F');" onmouseout="change_bg_color(this, '');">
Cell text</td>

vickers_bits
12-15-2002, 07:33 AM
sorry my bad
you can't pass -this-keyword

put id="whatever" in the cell
and pass "whatever" as the first parameter instead of this