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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:35:35+00:00 2026-05-14T04:35:35+00:00

I have some table structure: <tr class=row-2><tr> <tr class=row-3>..<tr> <tr class=row-4>..<tr> <tr class=row-5>..<tr> <tr

  • 0

I have some table structure:

    <tr class="row-2"><tr>
    <tr class="row-3">..<tr>
    <tr class="row-4">..<tr>
    <tr class="row-5">..<tr>
    <tr class="row-6">..<tr>
    <tr class="row-7"><tr>
    <tr class="row-8">..<tr>
    <tr class="row-9">..<tr>
    <tr class="row-10">..<tr>
    <tr class="row-11">..<tr>
...etc

for this example TR with classes “row-2” and “row-7” is parrent product link wich expand child rows.

<script>
$(function() {
    $('tr.parent')
        .css("cursor","pointer")
        .css("color","red")
        .attr("title","Click to expand/collapse")
        .click(function(){
            $(this).siblings('.child-'+this.id).toggle();
        });
    $('tr[@class^=child-]').hide().children('td');
});
</script>

Rows -3…-6 is child of row-2
and
Rows -8…-11 is child of row-7

How can I find row-2, row-7, etc then add second class “parent” and ID similar class (id=”row-2″, id=”row-7″, etc)? Also I need add in each TR between row-2 and row-7 class equal previous parent row. In bottom line I need something like this:

        <tr class="row-2 parent" id="row-2"><tr>
        <tr class="row-3 child-row2">..<tr>
        <tr class="row-4 child-row2">..<tr>
        <tr class="row-5 child-row2">..<tr>
        <tr class="row-6 child-row2">..<tr>
        <tr class="row-7 parent" id="row-7"><tr>
        <tr class="row-8 child-row7">..<tr>
        <tr class="row-9 child-row7">..<tr>
        <tr class="row-10 child-row7">..<tr>
        <tr class="row-11 child-row7">..<tr>
..etc
  • 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-05-14T04:35:36+00:00Added an answer on May 14, 2026 at 4:35 am

    One way is to do a two-pass on all rows, to set up the required classes and id’s. In the first pass, add an id same as the class name, and also add the parent class to row-2, and row-7. In the second pass, find each .parent row, and add child-<id> class to their siblings until the next parent. Instead of hard-coding the values for row-2 and row-7, this assumes that all header items are contained inside a <th> element, instead of a <td> element.

    Here’s some code: http://jsfiddle.net/vYTW2/

    /**
     * Do a two pass on all rows to set them up.
     * In the first pass, add the same id as class, and
     * add the "parent" class to the row.
     *
     * Assuming all product header rows contain a
     * <th> element
     */
    $('table tr th').each(function() {
        var row = $(this).parent('tr');
        var id = row.attr('class');
        row.attr('id', id);
        row.addClass('parent');
    });
    
    /**
     * In the second pass, run through all header rows
     * (that have the class parent) and mark all next siblings
     * with class "child-rowX" until we see the next parent row.
     */
    $('tr.parent').each(function() {
        var id = $(this).attr('id');
        var className = 'child-' + id;
        $(this).nextUntil('.parent').addClass(className);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I have a simple table that has this structure: <table> <thead> <tr> <td>Some info</td>
My html contains a table have the structure like this <table id=sample> <tr class=new_input_field>
UPDATED: I have some table with sync_numbers, like this: --------------------- id | sync_number ---------------------
Fiddle: http://jsfiddle.net/MhWm5/16/ I have some dynamically generated table rows/values with dynamic IDs <td class=control-group>
I have the following table structure <table class=ms-listviewtable> <tr> <td class=ms-vb2-icon/> <td class=ms-vb2/> <td
I have a table structure looking something like this. One outer table and in
I have a table that per row has some inputs and one edit button.
I have an existing table structure that looks something like this: AnimalTable ------------- |Id
I have some table: Title 1 | Title 2 | Title 3 | --------------------------------------------------

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.