faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 9 people (78%) answered Yes
Recently 7 of 9 people (78%) answered Yes

Entry

How do I alternate the color of a <tr> when someone clicks within the row?

Apr 7th, 2008 22:52
ha mo, Dave Clark, Klaus Bolwin, Chris Cote,


<tr onclick="this.style.color = 'red';">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Chris,
Since you asked for alternating colors, try this:
function alternate_color(obj, color1, color2)
{
    if (obj.style.color == color2)
    {
        obj.style.color = color1;
    }
    else
    {
        obj.style.color = color2;
    }
    return true;
}
<tr onclick="return alternate_color(this, 'yellow', 'blue')">
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com