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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:34:36+00:00 2026-06-04T20:34:36+00:00

I have a series of rows with different classes. <tr class=head>… <tr class=group>… <tr

  • 0

I have a series of rows with different classes.

<tr class="head">...
<tr class="group">...
<tr class="item">...
<tr class="item">...
<tr class="item">...
<tr class="group">...
<tr class="item">...
<tr class="item">...
<tr class="item">...
<tr class="group">...
<tr class="item">...
<tr class="item">...
<tr class="item">...

Assuming my context is at one of the items, how do I select all the rows before, after and including it, that are items, without crossing over a group?

In this example, no matter what item row I am at, I should always result in a collection of three item rows.

Currently I have this, and while it works, I’m hoping there is a cleaner way.

var $itemRows = $targetRow.prevUntil('tr.group').add($targetRow.nextUntil('tr.group')).add($targetRow);

Something like .siblings('tr.item') but that will get all nine items, instead of the three contigous ones. And I can’t put these in tbodies, as this is already in a tbody and nesting them is invalid html.

I have improved it to

var $itemRows = $targetRow.prevAll('tr.group:first').nextUntil('tr.group');
  • 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-04T20:34:37+00:00Added an answer on June 4, 2026 at 8:34 pm

    Assuming this is one of the rows (and not a group), you could do this:

    After testing out many scenarios, this is what I found worked:

    $(this).prevUntil('tr.group').andSelf().nextUntil('tr.group').andSelf()
    

    The issue is that when you click on the first item in a group, other combinations like gdoron’s didn’t work for me.

    You can see this one work here: http://jsfiddle.net/jfriend00/mks74/


    I thought there must be a bit cleaner way, so I kept working on it and this is what I found:

    $(this).prevAll('tr.group:first').nextUntil('tr.group')
    

    You can see this one work here: http://jsfiddle.net/jfriend00/HZVnX/


    What would be useful here (which jQuery does not seem to provide) is a jQuery method that gets the prior sibling that meets some selector criteria. We could make our own like this:

    jQuery.fn.prior = function(selector) {
        return (this.pushStack(this.prevAll(selector).first()));
    };
    

    And, then the code to solve this issue becomes a little more logical to read:

    $(this).prior('tr.group').nextUntil('tr.group')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if I have a series of subplots with one column and many rows, i.e.:
I have a series of annual incident counts per category, with no rows for
I have a series of select boxes within a table like so: <tr> <td><select></select></td>
I have a 300.000 rows table; one of the columns is a varchar() but
I have a series of DataRow objects, each with a bunch of different fields.
I have generated a series of rows using C# and VSTO. I have basically
I have a series of table rows like this: <cfloop query=qryPlayer> (...snip...) <input data-playerid=#PlayerID#
i have a series of rows that are generated using an asp:repeater : <asp:repeater
I have a series of a series of rows and checkboxes to filter them:
I have a series of parameters stored in rows in the database, and I'd

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.