Toggling row colors

Posted by cf_PhillipSenn on Stack Overflow See other posts from Stack Overflow or by cf_PhillipSenn
Published on 2010-04-16T15:02:07Z Indexed on 2010/04/16 15:23 UTC
Read the original article Hit count: 129

Filed under:

I have a table cell in the footer that allows the user to turn on row coloring:

$('#highlight').click(function() {
$(this).parents('table').RowColors();
})

// From Chapter 7 of Learning jQuery
$.fn.RowColors = function() {
$('tbody tr:odd', this).removeClass('even').addClass('odd');
$('tbody tr:even', this).removeClass('odd').addClass('even');
return this;
};

Q: How do I write a selector that says: IF there is at least 1 row with class="even", then remove both "even" and "odd" ELSE execute the RowColors function.

© Stack Overflow or respective owner

Related posts about jQuery