This should work, too* :
$("table.xy tr:visible:odd").addClass("odd")
* Might not work after first table if more than one <table
class="xy"> exists on the same page.
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Jul 5, 2007, at 1:03 PM, Scott Sauyet wrote:
backflip wrote:
I'm using the following code to style a table:
$("table.xy tr:nth-child(odd)").addClass("odd");
But before doing that I'm hiding some rows:
$("tr#xy").hide();
Now the zebra pattern isn't working any more (it's an abnormal
zebra), of
course. How to apply the zebra-stuff just to the visible rows?
This is not tested, but something like this might do it:
$("table.xy tr:visible").each(function(index) {
if (index %2 == 1) {
$(this).addClass("odd");
}
});
But if rows are being dynamically hidden and shown, you will need
an "else" and some "removeClass()" calls after each change to the
rows' visibility.
Cheers,
-- Scott