changing bgcolor of a row in html table


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: changing bgcolor of a row in html table

  1. #1
    praveen srinivas Guest

    changing bgcolor of a row in html table


    please suggest me the code to change the the background color of a row in
    html table using javascript onclick function on the <tr>
    tag.

    hoping the reply soon
    praveen

  2. #2
    Peter Stephens Guest

    Re: changing bgcolor of a row in html table


    The following html text should do the trick:

    <html>
    <title></title>

    <script language=javascript>
    function changeBackground()
    {
    event.srcElement.parentElement.style.backgroundColor="yellow";
    }
    </script>

    <body>
    <table>
    <tr onclick="changeBackground()">
    <td>test</td>
    <td>test2</td>
    </tr>
    </table>
    </body>

    </html>

    Since the source of the event is the <TD> element, you have to call the parent
    element of the <TD> element to get the <TR> element. You choose another color
    by putting another color in the function



    "praveen srinivas" <srinivas_alwala@semanticspace.com> wrote:
    >
    >please suggest me the code to change the the background color of a row in
    >html table using javascript onclick function on the <tr>
    >tag.
    >
    >hoping the reply soon
    >praveen



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center