faqts : Computers : Programming : Languages : JavaScript : Tables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

161 of 180 people (89%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do i change the bgcolor of a table column (TD) when a onMouseOver event on text in it occurs?

Aug 16th, 2000 03:28
Rey Nuņez, mark wouters, Martin Honnen,


Here is a simple example that actually works for single cells, not 
columns, but works in IE4/5 and NN4/6.
<script language="JavaScript">
<!--
function chgBg(obj,color){
if (document.all || document.getElementById)
  obj.style.backgroundColor=color;
else if (document.layers)
  obj.bgColor=color;
}
//-->
</script>
<table width=150>
<tr>
  <td onMouseover="chgBg(this,'khaki')" onMouseout="chgBg
(this,'white')"><ilayer width=100%><layer width=100% onMouseover="chgBg
(this,'khaki')" onMouseout="chgBg(this,'white')">Menu item 
1</ilayer></layer></td></tr>
<tr>
  <td onMouseover="chgBg(this,'orange')" onMouseout="chgBg
(this,'white')"><ilayer width=100%><layer width=100% onMouseover="chgBg
(this,'orange')" onMouseout="chgBg(this,'white')">Menu item 
1</ilayer></layer></td></tr>
</table>
The <layer><ilayer> sandwich is necessary for NN4, as it does not 
support changing background colors on table cells on mouse events.