Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3274930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:05:26+00:00 2026-05-17T19:05:26+00:00

I have a data table with alternating row background colors. I have an AJAX

  • 0

I have a data table with alternating row background colors. I have an AJAX script to delete a row. I can’t come up with a way to change the class of all the rows beneath the one that was deleted so that it alternates correctly again.

For example, considering the following:

`<tr id="1" class="row1">
   <td>blah</td>
 </tr>
 <tr id="2" class="row2">
   <td>blah</td>
 </tr>
 <tr id="3" class="row1">
   <td>blah</td>
 </tr>
 <tr id="4" class="row2">
   <td>blah</td>
 </tr>`

Now, using my AJAX script, I remove id2, then id3 will move underneath id1 and they will have the same row color. I managed to make my script change the next tr class, but that doesn’t really help because then it’s just the same color as the one after that. I can’t figure out how to iterate through all of the next tr’s, and change their class accordingly.

What I have so far:

$('#news_' + id).fadeOut('slow');

var currtr = $('#news_' + id).attr('class');
var nexttr = $('#news_' + id).closest('tr').next('tr').attr('id');

$('#' + nexttr).removeClass($('#' + nexttr).attr('class'));
$('#' + nexttr).addClass(currtr);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:05:27+00:00Added an answer on May 17, 2026 at 7:05 pm

    You could just iterate over the visible<tr> elements, and remove the class from the even ones, and apply to the odd ones.

    Something like this:

    Example: http://jsfiddle.net/2CZdT/

    $('tr:odd').addClass('odd');
    
    $('td').click(function() {
        $(this).parent().fadeOut(function() {
            $(this).siblings('tr:visible').filter(':even').removeClass('odd')
                .end().filter(':odd').addClass('odd');
        });
    });​
    

    I have the click event on the <td>, so when one is clicked, it traverses up to the parent <tr> element, fades it out, the in the callback, it grabs all visible sibling <tr> elements, filters the even ones, removes the .odd class, then goes back and filters the odd ones, and adds the .odd class.

    Note that this presumes there’s a default class applied in your CSS, then you override the odd ones (or even ones) with the alternating class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data table filled with text in each table row. How do
I have a script to extract certain data from a much bigger table, with
I have a row of data in dict format. Is there an easy way
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work
I have a data table which already has some values, plus it is getting
I have a data Table with numbers formatted according to the current regional settings.
Ok I have a data table containing duplicate Reciept numbers and a transaction value
In my SQL Server database schema I have a data table with a date
I'm a bit confused on this. I have a data table structured like this:
I have data from a table in a database (string) that contain text and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.