Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to use style object

    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?

    Code:
    <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!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,859
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    <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>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OH OKAY thank you very much!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •