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 8109391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:24:27+00:00 2026-06-06T01:24:27+00:00

I have been banging my head on this one for too long. I have

  • 0

I have been banging my head on this one for too long.

I have a basic table (all the TR’s except the ones that include th’s are classes with classme)

<table>
<tr class="classme"><td>1</td></tr>
<tr class="classme"><td>1a</td></tr>
<tr class="classme"><td>2</td></tr>
<tr class="classme"><td>2a</td></tr>
<tr><th>skip me</th></tr>
<tr class="classme"><td>3</td></tr>
<tr class="classme"><td>3a</td></tr>
<tr ...><td>4</td></tr>
<tr ...><td>4a</td></tr>
<tr ...><td>5</td></tr>
<tr><td>5a</td></tr>
<tr><td>8</td></tr>
<tr><td>8a</td></tr>
<tr><td>9</td></tr>
<tr><td>9a</td></tr>
<tr><td>10</td></tr>
<tr><td>10a</td></tr>
<tr><th>skip me</th></tr>
<tr><td>11</td></tr>
<tr><td>11a</td></tr>
<tr><td>12</td></tr>
<tr><td>12a</td></tr>
</table>

That I would like to stripe with a tr background color.

I am using jQuery and have found a few posts on here and Google relate to the stripping but have failed to find something that skips arbitrary rows.

I have attempted…

$("tr:nth-child(4n)").addClass("alt").prev().addClass("alt");

which works great, but it counts the ones I want to skip.

and

$("tr:not(tr th):nth-child(4n)").addClass("alt").prev().addClass("alt");

with no luck. I even tried to assign a variable to the result of

var trs = $(".classme"); 
$(trs + ":nth-child(4n)").addClass("alt").prev().addClass("alt");

but it still counted applied the style incorrectly.

How do I set a set of selected elements such that the rows I want to exclude are not in the count when the add class is put onto the element?

Edit:
I would like to stripe (in the table example) 1,1a,3,3a,5,5a. So I consider 1 and 1a to be a group. I want to stripe every other group.

Edit:
updated with jsFiddle

  • 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-06-06T01:24:28+00:00Added an answer on June 6, 2026 at 1:24 am

    Try this:

    var rows=   $('.classme:last').nextAll().not(':has(th)');
    rows.filter(':even').addClass('evenClass)
    

    Edit .skips lower th tag now

    DEMO http://jsfiddle.net/YXDMH/

    EDIT: all rows without TH included

    var rows=   $('tr').not(':has(th)');
    rows.filter(':even').addClass('evenClass').end().filter(':odd').addClass('odd')
    

    http://jsfiddle.net/YXDMH/1/

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

Sidebar

Related Questions

I've been banging my head against this for too long. I have two ViewControllers
I've been banging my head against this one all day long. Time to ask
I have been banging my head on this one all day. The C++ project
I have been banging my head on a wall with this one. I need
I have been banging my head on this one for hours and I am
This is to all the C# gurus. I have been banging my head on
I've been banging my head against the wall with this one. I have a
I've been banging my head for a long time on this one I am
Ok, I have been banging my head on this one for a while, figure
Ok I've been banging my head against this one so long, I think I've

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.