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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    184
    Thanks
    140
    Thanked 0 Times in 0 Posts

    Change Background Color of Row When Selected

    Hello,

    Given the following code below, how can I modify it such that it would change the background color of the selected row. It currently works great if a single cell is selected but i'd like to have it modified such that the selected row color is changed:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    var ie = document.all
    var ns = document.getElementById && !ie
    function rowclick(e) {
    var obj = ns ? e.target : event.srcElement
    if (obj.tagName=="TD") {
    obj.style.background="red"
    obj.onblur=function() {
    obj.style.background="white"
    }
    }
    }
    document.onclick=rowclick
    </script>
    </head>
    <body>
    <table width="320" cellspacing="1" border="1">
    <tr>
    <td width="127">Bananas</td>
    <td width="101">123</td>
    <td>red</td>
    </tr>
    <tr>
    <td width="127">Pears</td>
    <td width="101">456</td>
    <td>blue</td>
    </tr>
    <tr>
    <td width="127">Mangos</td>
    <td width="101">789</td>
    <td>green</td>
    </tr>
    <tr>
    <td width="127">Apples</td>
    <td width="101">012</td>
    <td>yellow</td>
    </tr>
    </table>
    </body>
    </html>
    Any help with this is greatly appreciated.

    Much thanks for all your help and support in advance.

    Cheers,

    Jay

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    How about like:

    Code:
    obj.parentNode.style.background="red"
    Out of head.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • Users who have thanked BubikolRamios for this post:

    jason_kelly (07-11-2012)


  •  

    Posting Permissions

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