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

  • Home
  • SEARCH
  • 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 164167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:41:46+00:00 2026-05-11T11:41:46+00:00

I am currently using the following jQuery script to highlight rows in my table,

  • 0

I am currently using the following jQuery script to highlight rows in my table, and it works great!

   <script type='text/javascript'>         $(document).ready(function()         {             $('table.grid tbody tr:odd').addClass('alt');         });     </script> 

This works great for tables of data where each row is truly a new record, however, I have run into an issue where I have records that take up two rows of data and would like to modify the jQuery so it renders something like:

<table>     <thead>         <tr>             <th>Col 1</th>             <th>Col 2</th>         </tr>     </thead>     <tbody>         <tr>             <td>Record 1 Field 1</td>             <td>Record 1 Field 2</td>         </tr>         <tr>             <td colspan='2'>Record 1 Field 3</td>         </tr>         <tr class='alt1'>             <td>Record 2 Field 1</td>             <td>Record 2 Field 2</td>         </tr>         <tr class='alt2'>             <td colspan='2'>Record 2 Field 3</td>         </tr>         <tr>             <td>Record 3 Field 1</td>             <td>Record 3 Field 2</td>         </tr>         <tr>             <td colspan='3'>Record 1 Field 3</td>         </tr>         <tr class='alt1'>             <td>Record 4 Field 1</td>             <td>Record 4 Field 2</td>         </tr>     <tr class='alt2'>         <td colspan='4'>Record 2 Field 3</td>     </tr> </tbody> </table> 

How would I accomplish this in jQuery where I want every 3rd row to have a class of ‘alt1’ and every 4th row to have a class of ‘alt2’?

  • 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. 2026-05-11T11:41:47+00:00Added an answer on May 11, 2026 at 11:41 am

    The above answer is slightly correct. Instead of using i%3==0 and i%4==0, use the same modulus divisor. So, starting at 0, i%4==2 and i%4==3 would skip two, take two, skip two, take two, etc. The other way takes the 3, 4, 6, 8, 9, 12, etc. So, minor modification would be

    <script type='text/javascript'>     $(document).ready(function()     {         $('table.grid tbody tr').each(function(i) {             if(i%4 == 2) {                 //Each 3rd row in sets of 4                 $(this).addClass('alt1');             }             if(i%4 == 3) {                 //Each 4th row in sets of 4                 $(this).addClass('alt2');             }         });     }); </script> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using this jQuery Cycle Plugin: http://jquery.malsup.com/cycle/ And I have the following code:
Using jQuery UI , I have a tabs plugin and within tab 1 gets
I'm receiving a Resource interpreted as script but transferred with MIME type application/json error
I am using two wordpress plugins WP-Cycle and NextGen-Gallery. Both these plugins use jquery
I have the following page layout using the 960 grid systm ---------------- header -----------------
currently i try to create a push server instance for new activities around our
UPDATE 3: The following does not seem to make any difference, does exactly the
I'm using the madebydna version of Ryan Bates' nested_form gem from GitHub (can be
I would like to fetch the WikiText from a Wikipedia page and display it
I'm converting an existing ASP.NET app to MVC2, and I have an existing method

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.