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>
精彩评论