change the color of one cell when mouseover another cell

This should be straight forward, but I'm having some trouble getting the object reference right.

I have a table with two cells.  When I move the mouse over one cell, I want to change the font color of the other.

This does not seem to work:

<table>
<tr>
<td id="cell1">some text</td>
<td onmouseover="cell1.style.color='red'>move mouse here</td>
</tr>
</table>

In the above, I get an "'cell1.style' is null or not an object"

Could someone please give me the right syntax for this.  Thanks in advance!
quiTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dalsymCommented:
try

<table>
<tr>
<td name="cell1">some text</td>
<td onmouseover="cell1.style.color='red'>move mouse here</td>
</tr>
</table>

Sometimes I'll run into that and using name instead of id (or vice/versa) sometimes helps.

You'll also probably want to do an onmouseout to restore the cell back to the original color once they leave the cell.

Good luck
0
quiTechAuthor Commented:
Hmmm... when I try this, I get "cell1 is undefined" error.
0
UnexplainedWaysCommented:
Here's a basic version:


<html>
<head>
<script language=javascript>

      function DoThat()
      {
            element = document.getElementById("cell1");
            element.style.color='red';
      }

</script>
</head>
<body>

<table>
<tr>
<td id="cell1">some text</td>
<td onmouseover="DoThat()">move mouse here</td>
</tr>
</table>


</body>
</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UnexplainedWaysCommented:
And this is a bit more extendable:


<html>
<head>
<script language=javascript>

      function DoThat(theID,theStatus)
      {
            element = document.getElementById(theID);
            if(theStatus)
            {
                  //Mouse over
                  element.style.color='red';
            }
            else
            {
                  //Mouse out
                  element.style.color='black';
            }
      }

</script>
</head>
<body>

<table>
<tr>
<td id="cell1"
    onmouseover="DoThat('cell1',true)"
    onmouseout ="DoThat('cell1',false)"
>some text1</td>

<td id="cell2"
    onmouseover="DoThat('cell2',true)"
    onmouseout ="DoThat('cell2',false)"
>some text2</td>

<td id="cell3"
    onmouseover="DoThat('cell3',true)"
    onmouseout ="DoThat('cell3',false)"
>some text3</td>

<td id="cell4"
    onmouseover="DoThat('cell4',true)"
    onmouseout ="DoThat('cell4',false)"
>some text4</td>

<td id="cell5"
    onmouseover="DoThat('cell5',true)"
    onmouseout ="DoThat('cell5',false)"
>some text5</td>

</tr>
</table>

</body>
</html>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.