It'll be more efficient if you store the elements you're going to manipulate into a variable. Also, since you're doing the same thing twice, you could make it into a function.
e.g. <script type="text/javascript"> $(document).ready(function() { var getTrs = $('tbody.bevker tr'); function changeTrs(){ getTrs.each(function(i){ $(this).removeClass(); (i%2)? $(this).addClass('row0 odd') : $(this).addClass('row1 even'); }); }; changeTrs(); $('th').click(function() { changeTrs(); return false; } ); } ); </script> On Oct 19, 12:02 am, FrankTudor <[EMAIL PROTECTED]> wrote: > Here is a bit of code that on page load sets the alternating color of > a table. > > Then there is a table sort tool that loads as well. The th (header) > clicks cause the nice alternating line colors to sort as well. So I > created this, which works perfect, but it looks clunky/repetitive.. > > I was thinking about wrapping an if statement in here somewhere, or > maybe there is something else other people can think of. > > <script type="text/javascript"> > $(document).ready(function() > { > $('tbody.bevker tr:odd').removeClass(); > $('tbody.bevker tr:even').removeClass(); > $('tbody.bevker tr:odd').addClass('row0 odd'); > $('tbody.bevker tr:even').addClass('row1 even'); > > $('th').click(function() > { > $('tbody.bevker tr:odd').removeClass(); > $('tbody.bevker tr:even').removeClass(); > $('tbody.bevker tr:odd').addClass('row0 odd'); > $('tbody.bevker tr:even').addClass('row1 even'); > return false; > } > ); > } > ); > </script>