+ Start a Discussion
prakash chaudharyprakash chaudhary 

Change color of row in javascript ...

Please tell me how to set background color dynamically by javasrcript ?

Since I am creating table in page but I want that its even number row must have color light grey & odd number row must have color light blue.

Please tell me how to do it ?

SInce I tried to make it by taking total number of row by javascript & in condition give color to their row but could not get any effect so please help me.

Best Answer chosen by Admin (Salesforce Developers) 
SarvSarv
create two css.
.odd{
...set your background color ........
}
.even{
...set different background color ........
}
<apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even"styleClass="tableClass">

All Answers

Shashikant SharmaShashikant Sharma
var elementObj = document.getElementById('Put ID of your control');
elementObj.style.backgroundColor= "yellow";
                                            
//You can use color code as well                                                   elementObj.style.backgroundColor= "#00FF00";
                               
                                                   

Try above code it will set background color

SarvSarv
create two css.
.odd{
...set your background color ........
}
.even{
...set different background color ........
}
<apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even"styleClass="tableClass">
This was selected as the best answer