开发者

Removing a HTML class from specific elements in an alternating row table

开发者 https://www.devze.com 2023-03-26 12:36 出处:网络
I have a script that detects if a row is odd and adds a HTML class named \'alt\'. Some rows in this table are chapters and should have the \'chapter\' class assigned (I have just a few chapter rows

I have a script that detects if a row is odd and adds a HTML class named 'alt'.

Some rows in this table are chapters and should have the 'chapter' class assigned (I have just a few chapter rows so the class is assigned manually). I want to remove/toggle the 'alt' class for these elements (if they fall in the odd range).

The script:

<script>
$(document).ready(function(){
    var row=0;
    $('table.features-table tbody tr').each(function() {
        row++;
        if(row%2==0) {
          $(this).addClass('alt');
                  }

     开发者_C百科   if(document.getElementById('table.features-table tbody tr').className("chapter")) {
          $(this).removeClass('alt');
                }       
            });
});
</script>


Does this work for you?

<script>
$(document).ready(function(){
    var row=0;
    $('table.features-table tbody tr').each(function() {
        row++;
        if((row % 2 == 0) && ($(this).children('.chapter').length == 0)) {
          $(this).addClass('alt');
        }
     });
});
</script>
0

精彩评论

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