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 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 the following jQuery plugin: jQuery OEmbed. This plugin works great in
I have the following script at the end of my page: <script type=text/javascript> jQuery.noConflict();
I currently have the following JavaScript/jQuery script that gets an external html page using
I am currently using the following script to set this value as a String:
I am using the following sliding div script: http://www.webdesignerwall.com/demo/jquery/simple-slide-panel.html Currently, the slidetoggle function is
I am using the following JQuery\JavaScript code to communicate with a WCF 4 REST
I'm using the following jQuery script to calculate the total width of ul based
I'm currently using this jQuery Cycle Plugin: http://jquery.malsup.com/cycle/ And I have the following code:
I'm currently building a website using jquery. I've found a script which will cause
I am currently working on a project using jQuery and JavaScript. There will be

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.