Jump to content

odd/even colors


techker

Recommended Posts

Hey guys i have a script that has accordian content but i would like it to have odd and even colors?

 

Dj2sFUc.jpg

<div id="va-accordion" class="va-container">
              
<div class="va-wrapper">
               
               <?php while($info = mysql_fetch_array($result)){?>
<div class="va-slice va-slice-1">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td rowspan="2" valign="top"><img src="images/recent3.jpg" width="160" height="140" ></td>
    <td valign="top">  <h3 class="va-title">  <? echo $info['Make'] ?> <? echo $info['Model'] ?> <? echo $info['Year'] ?></h3></td>
  </tr>
  <tr>
    <td valign="top"> </td>
  </tr>
                    </table>
<div class="va-content">
<p><div class="bubble"><? echo $info['Retail_price']?>$</p>
                            <? echo "<span class='echo_short'>".$info['Description_short_FR']."</span>"; ?>
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="16%"><img src="images/recent3.jpg" width="126" height="120" ></td>
    <td width="84%"><img src="images/recent3.jpg" width="126" height="120" ></td>
  </tr>
</table>
</div>          
</div>
</div> 
        <? } ?> 
        
          </div></div>

i tried:

 

 

 
.odd{
 color:red;  
}
 
.even{
 color:blue;   
}
 
 

<script type="text/javascript">
$(function(){
    $(".va-slice div.post:odd").addClass('odd'); 
    $(".va-slice div.post:even").addClass('even'); 
    
});
</script>
Link to comment
https://forums.phpfreaks.com/topic/285274-oddeven-colors/
Share on other sites

CSS3 provides a pseudo-selector for this called :nth-child. If you want something that works on much older browsers then you'll need to have your PHP code generate alternating class names, the most common method of which is using the modulus operator. eg:

 

$class = $rowNum%2?'odd':'even';
While you could apply the effect after the affect with jQuery (as you tried) it is unnecessary to involve Javascript in something such as this.
Link to comment
https://forums.phpfreaks.com/topic/285274-oddeven-colors/#findComment-1464791
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.