Hi there,

I currently have code in place to change the background colour of a cell in a table on mouseover, then change it back when the mouse is removed. What I would like to do is also change the foreground and font colour on mouseover, how do I go about doing this? My snippet of code is as follows:

<td onmouseover="this.style.backgroundColor='red';" 
                onmouseout="this.style.backgroundColor='#797B79';" class="style5">
                <a class="style2" href="http://www.google.com"><span class="style3">HOME</span></a></td>

Cheers for any help,


8 Years
Discussion Span
Last Post by Elbudster

You don't really need to use JavaScript to achieve that effect. All you need to do are add a few CSS styles to do that. In fact, the JavaScript you have embedded in there is essentially doing that anyways. Here is a little example html file I made from your snippet. I removed some of the styles you had added for simplicity. Hope this helps.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<title>CSS Example</title>
<style type="text/css">
table td.my_class {
	background-color: #ff0;
table td.my_class a {
	color: #f00;

/* mouseover styles */
table td.my_class:hover {
	background-color: #f00;
table td.my_class:hover a {
	color: #ff0;

		<td class="my_class">
			<a href="http://www.google.com">HOME</a>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.