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

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There's been a getters and setters ticket open in the… May 11, 2026 at 12:55 pm
  • added an answer Works for me. VIM 7.1. What output do you get… May 11, 2026 at 12:55 pm
  • added an answer Make the constructors in Player have package access only. Then… May 11, 2026 at 12:55 pm

Related Questions

I am currently using the following command to upload my site content: scp -r
I am currently using the following code to create a web request: Dim myRequest
I am currently using the UltraWebGrid control of Infragistics and I am displaying the
I am currently using TortoiseSVN to manage a couple of the projects that I
I am currently using SQL Server Management Studio (Ver 9.00.3042.00) and click the New
I have a simple HTML. I am using the JQuery for AJAX purpose. Now,
I am trying to make a navigation that uses simple unordered lists to list
I have a group of text based rules that are structured like this: Rule
I have a spec in my current project that requires us to advise the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.