Results 1 to 3 of 3

Thread: [Resolved] How to change table row color with JavaScript

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    38

    Resolved [Resolved] How to change table row color with JavaScript

    Hi, all,

    I have a question about javasrcipt. The following HTML page has a table composed of three rows. I wish to know how to find the yellow row and change its bgcolor to red? Use javascript.

    Thank you very much for any suggestion!
    xihu24


    Code:
    <html>
    <script lauguage="javascript">
    function findYellowRow(){
       // implementation to change the row from yellow to red
       // ?
    }
    </script>
    
    <body>
    <table>
    <tr bgcolor=white><td>1</td></tr>
    <tr bgcolor=yellow><td>2</td></tr>
    <tr bgcolor=white><td>3</td></tr>
    </table>
    
    <form>
    <input type="button" value="FindYellowRow" onClick="findYellowRow();">
    </form>
    </body>
    </html>
    Last edited by xihu24; Oct 29th, 2004 at 04:32 PM.

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I'm in hurry so a quickie:

    You could go through each td by first getting the table using an ID (getElementByID) and then look for .bgColor == "yellow"

    but it would be easier to do it with classes and stylesheets.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    38
    Hi, Job,

    Thank you very much. getElementByID() works fine.

    xihu24

Posting Permissions

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



Click Here to Expand Forum to Full Width