hmmm, tough one, it was fun.

$(function() {
    var color = '';
    $('#everyother tr').each(function() {
        if( $(this).hasClass('className') ) {
            color = 'red';
        } else if (color === 'red') {
            $(this).css({'background-color': 'red'});
            color = '';
        } else {
            color = 'red';
        }
    });

    <table id="everyother">
<tr class="className"><td>className</td></tr>
<tr><td>1</td></tr>
<tr><td>1</td></tr>
<tr class="className"></><td>className</td></tr>
<tr><td>1</td></tr>
<tr><td>1</td></tr>
<tr><td>1</td></tr>
<tr class="className"><td>className</td></tr>
<tr><td>1</td></tr>
<tr><td>1</td></tr>
</table>


On Feb 27, 9:03 am, Magritte <marco.oliva...@gmail.com> wrote:
> Ok, it work, but I another trouble.
>
> the code now become:
> $('tr:not(.className):odd').css({'background':'red'});
>
> because I would like to color row alternatively.
> The problem is that I would like that the alternativy start alway with
> red.(first '<tr>' after every '<tr class="className"></></tr>' red,
> then 'white', then red,....)
>
> With this code it doesn't happen.
>
> Thanks
>
> On 27 Feb, 13:17, Thomas Jaggi <thomas.ja...@gmail.com> wrote:
>
> > This should do it:
> > $('tr:not(.className)').css({'background':'red'});

Reply via email to