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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:07:35+00:00 2026-06-13T16:07:35+00:00

I have some extremely poorly formatted HTML code, where each element in a table

  • 0

I have some extremely poorly formatted HTML code, where each element in a table is a row. I want to group the sub-elements a little easier, by adding some HTML to the page. Here is a small example of the HTML:

<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <table width="100%">
      <tr class="heading">
        <td>value 1</td>
      </tr>
      <tr>
        <td>sub 1</td>
      </tr>
      <tr>
        <td>sub 1</td>
      </tr>
      <tr class="heading">
        <td>value 2</td>
      </tr>
      <tr>
        <td>sub 2</td>
      </tr>
      <tr class="heading">
        <td>value 3</td>
      </tr>
      <tr>
        <td>sub 3</td>
      </tr>
    </table>
  </body>
</html>​

I’d like to wrap each of the rows with a class of heading, with another tr or div or really anything to allow me to grab the sub-elements a bit easier. I’ve tried various combinations of before, html, etc.. yet I can’t seem to get this to work.

Here is a jsfiddle that I’ve put together. Any way to wrap the the tr values with a class of heading? For example, I’d like to grab the 3 rows with class heading in the sample HTML. I’d like to prepend that first row with some HTML, and close it before the start of the second row. I would repeat that process for each row (open a tag and close it before the next row), on the final row I would simply close it.

So the output I would like is:

<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <table width="100%">
      <SOME_TAG>
        <tr class="heading">
          <td>value 1</td>
        </tr>
        <tr>
          <td>sub 1</td>
        </tr>
        <tr>
          <td>sub 1</td>
        </tr>
      </SOME_TAG>
      <SOME_TAG>
        <tr class="heading">
          <td>value 2</td>
        </tr>
        <tr>
          <td>sub 2</td>
        </tr>
      </SOME_TAG>
      <SOME_TAG>
        <tr class="heading">
          <td>value 3</td>
        </tr>
        <tr>
          <td>sub 3</td>
        </tr>
      </SOME_TAG>
    </table>
  </body>
</html>​
  • 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-13T16:07:36+00:00Added an answer on June 13, 2026 at 4:07 pm

    Based on kssr’s suggestion — wrap them in subtables using nextUntil and wrapAll

    $(document).ready(function()
        {
            wrapTR(0);
        });
    
        function wrapTR(index)
        {
            $('tr.heading:eq('+index+')').nextUntil('.heading').andSelf().wrapAll('<table class="useful-grouping" id="table-'+index+'"/>');
            if($('tr.heading:eq('+index+')').next('.heading'))
            {
                wrapTR(index+1)
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a client who desires some extremely long pages. Say 4000px plus. They
This is extremely strange, and I'm hoping someone will have some insights to make
I have some arbitrary pixel data that I want to save as a PNG.
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some table: Title 1 | Title 2 | Title 3 | --------------------------------------------------
I have some code that will change the background color of a specific label
I have some extremely weird behavior that seems to result in silent exceptions. How
I have some extremely complex queries that I need to use to generate a
I have a small db app that stores URL's of all lengths, some extremely
I have some JavaScript, which is generated by PHP code, using a template. The

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.