ole ole - 1 year ago 114
PHP Question

jquery & php color every other row

I want to make every other colored on my table here.
I have think about some jquery but I don't know what is best practice.. I hope some one can help me.

<table border="0" width="100%" cellpadding="0" cellspacing="0">
<td><i>Antal svar</i></td>
<td><i>Sidste svar af</i></td>
<?php foreach ($activeQuery as $activeThread): ?>
<td><a href="<?php echo base_url(); ?>forum/post/<?php echo $activeThread->traadID; ?>">
<?php echo $activeThread->traadOverskrift; ?></td>
<td><?php ?></td>
<td><?php echo $activeThread->kommentareBrugernavn; ?></td>
<td><abbr class="timeago" title="<?php echo $activeThread->kommentareDato; ?>">
<?php echo $activeThread->kommentareDato; ?></abbr></td>
<?php endforeach ?>

Answer Source

Maybe the nth-child() selector is a better choice for this case

$("tr:nth-child(even)").css("backgroundColor", "#bbbbff");


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download