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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onmouseover change <TR> with colored <TD>s 1

Status
Not open for further replies.

feshangi

MIS
Nov 24, 2004
265
US
I have below <TR>:

Code:
<tr>
<td bgcolor="Red"></td>
<td bgcolor="Blue"></td>
</tr>

Is it possible to change the <TR> background color onmouseover and onmouseout put the default colors back to <TD>s?

On my actual scenario I have a lot more <TD>s.

Thanks in advanced,

Mike
 
How 'bout this?
Code:
<script type="text/javascript">
function changeBG(objRow, mouseState)
    {
    if (mouseState == 'on')
        {
        	sColor = '#eeeeee';			
			tColor = '#000000';
    }
    else if (mouseState == 'off')
        {
        	sColor = '#FFFFFF';
			tColor = '#000000';
    }
    objRow.bgColor = sColor;
	objRow.style.color = tColor;
	}
</script>


<tr onMouseOver="changeBG(this, 'on');" onMouseOut="changeBG(this, 'off');">
  <td bgcolor="Red"></td>
  <td bgcolor="Blue"></td>
</tr>
Change 'sColor' and 'tColor' to be whatever colors you want to use.



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Ecobb, I don't know what to do without you.

As always thanks.

Mike
 
try this too:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

<html>
<head>
<title>Untitled</title>

<style type="text/css">

.c1 { background-color: red; }
.c2 { background-color: green; }
.c3 { background-color: gray; }
.c4 { background-color: yellow; }
.c5 { background-color: aqua; }

.cellOver { background-color: white; }

</style>

<script language="javascript"><!--

function changeColor(blnOver, rowTarget) {
    var cells = rowTarget.cells;
    for (var i = 0; i < cells.length; i++) {
        cells[i].className = (blnOver) ? "cellOver" : ("c" + (i + 1))
    }
}

--></script>
</head>

<body>

<table><tr onmouseover="changeColor(true, this);" onmouseout="changeColor(false, this);">
<td class="c1">Stuff</td>
<td class="c2">Stuff</td>
<td class="c3">Stuff</td>
<td class="c4">Stuff</td>
<td class="c5">Stuff</td>
</tr><tr onmouseover="changeColor(true, this);" onmouseout="changeColor(false, this);">
<td class="c1">Stuff</td>
<td class="c2">Stuff</td>
<td class="c3">Stuff</td>
<td class="c4">Stuff</td>
<td class="c5">Stuff</td>
</tr><tr onmouseover="changeColor(true, this);" onmouseout="changeColor(false, this);">
<td class="c1">Stuff</td>
<td class="c2">Stuff</td>
<td class="c3">Stuff</td>
<td class="c4">Stuff</td>
<td class="c5">Stuff</td>
</tr></table>

</body>
</html>

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
Ecobb, I am facing the same problem that I had originally. Whatever code I try won't overwrite the <TD>s color!
 
Thanks cLFlaVA for the code. The problem I have with it is on mouseover it make the fonts bigger. My font is set to 10px but onmouseover the font is changing to something like 12px. Do you know why this is happening?

Thanks,

Mike
 
Add an additional style:

Code:
<style type="text/css">

[blue]td { font-size: 10px; }[/blue]

.c1 { background-color: red; }
.c2 { background-color: green; }
.c3 { background-color: gray; }
.c4 { background-color: yellow; }
.c5 { background-color: aqua; }

.cellOver { background-color: white; }

</style>

Make sure you don't have any other overriding styles that might be doing that.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
For the record (and not to confuse), the above style changes can be achieved in most non-IE browsers without any JavaScript. Simply make the style as follows:

Code:
<style type="text/css">

.c1 { background-color: red; }
.c2 { background-color: green; }
.c3 { background-color: gray; }
.c4 { background-color: yellow; }
.c5 { background-color: aqua; }

tr:hover td { background-color: white; }

</style>
And then remove all the JavaScript from your page.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
Then provide your complete code. No one here is a mindreader.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
From my experience, changing the style of a table row may not necessarily change the style of table cells, especially if the cells have their own style.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Code:
<tr onmouseover="changeColor(true, this);" onmouseout="changeColor(false, this);">
                            <td width="37" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">#CustNum#</div></td>
                            <td width="153" bgcolor="#WorkFlowColumnB#" class="style4">#PlanCodeId#</td>
                            <td width="45" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnB#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnB#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnB#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnB#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnB#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnB#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnA#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="45" bgcolor="#WorkFlowColumnB#" class="style4"><div align="center">09/09/09</div></td>
                            <td width="70" class="style4">#Left(Note,14)#</td>
                          </tr>
 
tsdragon, have you read any of the posts?

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
feshangi, that's nice code, but I'll need to see the style definitions as well. you don't need a <div> in there. if you get rid of the <div> and make your style as follows:

Code:
<style type="text/css">

td { font-size: 10px; }

.c1 { background-color: red; }
.c2 { background-color: green; }
.c3 { background-color: gray; }
.c4 { background-color: yellow; }
.c5 { background-color: aqua; }

.cellOver { background-color: white; }

.c1, .c2, .c3, .c4, .c5, .cellOver { text-align: center; }

</style>

Does that fix your problem? Again, if it doesn't, please show ALL your code. The code you showed does not reflect the problem.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
cLFlaVA,

You were right. I had other styles overriding your codes.

This is what was causing it:

body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
}

Now it's exactly how I wannted. You are a mindreader :)

Thanks,

Mike
 
no prob.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
Hey, that's pretty slick! I wish I knew enough css to come up with stuff like that! :)



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
cLFlaVA: of course I've read the other posts! Is there some reason you asked?


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Because none of my posts talk about changing the color of <tr>, but rather <td>.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
From the original question:
Is it possible to change the <TR> background color onmouseover and onmouseout put the default colors back to <TD>s?

(emphasis mine)
That is what I was commenting on.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top