Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hover changes background color of cell

Status
Not open for further replies.

spyder

Technical User
Jan 10, 2001
21
0
0
US
Well, I've scrolled through what others have said about this, and haven't been able to decipher what I need to know.

I want to change the background color of table cells (in a navigation bar) as they are hovered over. I am familiar with HTML and CSS, but not Javascript.

How do I do this? Could you tell me what should go in the STYLE tag and the TABLE tag?

Thanks.



 
Hi spyder.

There are many solutions. This is only one:
(I thought it's IE only, didn't test it)

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function highlight(cell)
{
cell.bgColor = '#ffff00';
}

function normal(cell)
{
cell.bgColor = '';
}
</script>

<td onmouseover=&quot;highlight(this)&quot; onmouseout=&quot;normal(this)&quot;>
 
I might be mistaken, but I think you can do this with DIVS. Since DIVS work well in both netscape and IE, perhaps looking into this might be a good idea. ----------------------------------------
&quot;I got a fevah... and the only prescription is more cowbell!&quot;
 
Hi there,

Try this even...

<html>

<head>
<title>Cell Colours</title>
</head>

<body>

<table border=&quot;1&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;33%&quot; onMouseover=&quot;style.backgroundColor='red'&quot;
onMouseout=&quot;style.backgroundColor='blue'&quot; bgcolor=&quot;blue&quot;>cell</td>
<td width=&quot;33%&quot; onMouseover=&quot;style.backgroundColor='green'&quot;
onMouseout=&quot;style.backgroundColor='yellow'&quot; bgcolor=&quot;yellow&quot;>cell</td>
<td width=&quot;34%&quot; onMouseover=&quot;style.backgroundColor='orange'&quot;
onMouseout=&quot;style.backgroundColor='purple'&quot; bgcolor=&quot;purple&quot;>cell</td>
</tr>
</table>
</body>
</html>

<!-- :eek:) -->
 
Wow. Thanks everyone. You gave me great info, and it works!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top