Alternate Div background color

Hi,

Something is wrong that I am not sure what I'm doing wrong.

I'm trying to alternate my div to display a different color

this is what I have:

  <script language="JavaScript">
  
  $(document).ready(function(){

 $(".RuleDiv div:odd").css("background-color", "#F4F4F8");
 $(".RuleDiv div:even").css("background-color", "#EFF1F1");

  });

 </script>

Open in new window



<table style="width:100%;">
    <cfoutput query="SearchResult">
    <div class="RuleDiv">	    
     <tr> 
                 <td colspan="9" class="ListGridHdrRow">
                   <span style="font-weight:bold;">Version:</span>
    				#SearchResult.Version# &nbsp;  <span style="font-weight:bold;">CQ Ticket:</span> #SearchResult.CQticketNumber# &nbsp;  <span style="font-weight:bold;">Rule Identifier: </span>#SearchResult.RuleIdentifier#</td>
           		</tr>
 
            <tr>
            		<td style="padding-left:5px;font-weight:bold;">Case ID</td>
            		<td style="padding-left:5px;font-weight:bold;">Px</td>
            		<td style="padding-left:5px;font-weight:bold;">Dx</td>
            		<td style="padding-left:5px;font-weight:bold;">PassFail</td>
            		<td style="padding-left:5px;font-weight:bold;" colspan="2">Result</td>
            		<td style="padding-left:5px;font-weight:bold;">Created by</td>
            		<td style="padding-left:5px;font-weight:bold;">Created Date</td>
           		</tr>
     
                    		<cfquery name="SearchSubResult" datasource="#strDSN#" username="#strUID#" password="#strPWD#" result=	"DataSubResult">
                    select TS.ICDID, TS.CaseID, TS.RuleID, TS.Px, TS.Dx, TS.PassFail,
                    TS.Result, TS.CreatedDate, TS.ModifiedBy
                    from TestingICD TS
				    where TS.RuleID in (#SearchResult.RuleID#)
                     </cfquery>
              
             <!--- <cfdump var="#SearchSubResult#"> 
 <cfoutput>SQL: #DataSubResult.SQL#</cfoutput> --->
 
                        <cfif (isDefined("SearchSubResult") and #SearchSubResult.RecordCount# gt 0) >
                    <cfloop query="SearchSubResult">
                <tr>
            		<td style="font-weight:normal;padding-left:10px;">#SearchSubResult.CaseID#</td>
            		<td style="font-weight:normal;padding-left:10px;">#SearchSubResult.Px#</td>
            		<td style="font-weight:normal;padding-left:10px;">#SearchSubResult.Dx#</td>
            		<td style="font-weight:normal;padding-left:10px;">#SearchSubResult.PassFail#</td>
            		<td style="font-weight:normal;padding-left:10px;" colspan="2">#SearchSubResult.Result#</th>
            		<td style="font-weight:normal;padding-left:10px;">#SearchSubResult.ModifiedBy#</td>
            		<td style="font-weight:normal;padding-left:10px;">#Trim(DateFormat(SearchSubResult.CreatedDate, "mm/dd/yyyy"))#</td>
				</tr>  
				   </cfloop>
				</cfif> 
               <tr>
            		<td colspan="9">&nbsp;</td>
			  </tr>
              
              <tr>
              	<td colspan="11">&nbsp;
                
                </td>
              </tr>
          </div> 
	</cfoutput>

	</table>

Open in new window

lulu50Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Why not just use the CSS pseudo classes
.RuleDiv:nth-child(odd) {
  background-color: #F4F4F8;
}

.RuleDiv:nth-child(odd) {
  background-color: #EFF1F1;
}

Open in new window


Or if you want to do it in JQuery then use the nth-child selector like so
$(".RuleDiv div:nth-child(odd)").css("background-color", "#F4F4F8");
$(".RuleDiv div:nth-child(even)").css("background-color", "#EFF1F1");

Open in new window

Sample of both here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lulu50Author Commented:
Thank you Julian !!!!
lulu50Author Commented:
Thank you
Julian HansenCommented:
You are most welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.