开发者

jquery & php color every other row

开发者 https://www.devze.com 2023-02-18 04:05 出处:网络
I want to make every other colored on my table here. I have think about some jquery b开发者_JS百科ut I don\'t know what is best practice.. I hope some one can help me.

I want to make every other colored on my table here. I have think about some jquery b开发者_JS百科ut I don't know what is best practice.. I hope some one can help me.

<table border="0" width="100%" cellpadding="0" cellspacing="0">
    <tr>
        <td><i>Overskrift</i></td>
        <td><i>Antal svar</i></td>
        <td><i>Sidste svar af</i></td>
        <td><i>Dato</i></td>
    </tr>
<?php foreach ($activeQuery as $activeThread): ?>
    <tr>
        <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>
    </tr>
<?php endforeach ?>
</table>


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

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

http://api.jquery.com/nth-child-selector/


You can use the :even and/or :odd selector

$("tr:gt(0):even td").css("background-color", "#bbbbff");

or

$("tr:gt(0):odd td").css("background-color", "#bbbbff");

Documentation:

http://api.jquery.com/gt-selector/

http://api.jquery.com/even-selector/

http://api.jquery.com/odd-selector/

0

精彩评论

暂无评论...
验证码 换一张
取 消