Friday, January 1, 2010

Re: [jQuery] Re: jQuery does not stripe visible table rows correctly

Thank you all for your helpful suggestions.

On Fri, Jan 1, 2010 at 2:37 PM, Karl Swedberg <karl@englishrules.com> wrote:

On Jan 1, 2010, at 3:53 PM, Michael Geary wrote:

I wouldn't use either version.

Instead, I would change your CSS from:

tr.rowodd { background-color: #FFF; }
tr.roweven { background-color: #F2F2F2; }

to:

tr { background-color: #FFF; }
tr.roweven { background-color: #F2F2F2; }

and then use just one line of jQuery code:

    $('#foobar tr:visible:odd').addClass('roweven');

Now you're doing only half the work and letting the CSS cacading rules take care of the rest.

And if you need to support IE6, you might have trouble applying a background-color to a <tr> (I seem to recall having that problem in the past). If you do, you could do this instead:

tr td { background-color: #FFF; }
tr.roweven td { background-color: #F2F2F2; }


--Karl

____________
Karl Swedberg


No comments: