Jump to content

Change table row color from 2nd row onwards?


sayedsohail

Recommended Posts

Hi everyone,

 

I got a small problem, i am displaying data in a html table with five rows of five columns each, the first row is a title row with blue background, and the 2nd row onwards is the data rows with a radio button.

 

When a user click first row, nothing should happend, but when the user clicks the radio button or any column of the row, I wish to select the radio value (clicked) and set the background color to silver for the entire row of five columns.

 

Here is my javascript code which is working fine, except it removed the first row style background color, which I don't wish to remove.  any suggestions would be highly appreciated. 

 

 

var trs = document.getElementsByTagName('tr');

function color(obj)
{
    for(var i=0; i < trs.length; i++)
    {
        var cells = trs[i].getElementsByTagName('td');
        for(var p=0; p < cells.length; p++)
        {
              cells[p].style.backgroundColor='white';
        }
    }
    currentCells = obj.getElementsByTagName('td');
    for(var n=0;n<currentCells.length;n++)
    {
        currentCells[n].style.backgroundColor = 'silver';
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.