...

View Full Version : How to use style object



xxAlv1Nxx
06-27-2012, 04:20 PM
Hi, I am writing some code for a webpage. Essentially what I want this code to do is to change the text colour of an element and the background colour of another. I tried using the style object but I must have done something wrong because it's not working... I know that the script is retrieving the correct element so is there something wrong with my syntax for the style object?



<script type="text/javascript">
function hover(x)
{
var k=document.getElementById(x);
this.style.color="#000000";
k.style.backgroundColor="#000000";
}
</script>
...
<table><tr>
<td style="background-color:#aaaaaa;" id="a"/>
</tr>
<tr style="color:#aaaaaa;">
<td onMouseOver="hover('a')">home</td>
</tr></table>


Thank you!

abduraooft
06-27-2012, 04:24 PM
<script type="text/javascript">
function hover(obj,x)
{
var k=document.getElementById(x);
obj.style.color="#000000";
k.style.backgroundColor="#000000";
}
</script>
...
<table><tr>
<td style="background-color:#aaaaaa;" id="a"/>
</tr>
<tr style="color:#aaaaaa;">
<td onMouseOver="hover(this,'a')">home</td>
</tr></table>

xxAlv1Nxx
06-27-2012, 05:00 PM
OH OKAY thank you very much! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum