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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:31:38+00:00 2026-05-14T06:31:38+00:00

I can’t quite wrap my head around this one… A table like the one

  • 0

I can’t quite wrap my head around this one…

A table like the one below is spit out by a renderer from some XML. The XML it comes from has a variable depth. (Please point out if I’m using the rowspans in a horrific manner as well, I just came to this table with some experimentation).

<table border="1">
    <tr>
        <td rowspan="12">> 1</td>
    </tr>
    <tr>
        <td rowspan="3">1 > 2</td>
    </tr>
    <tr>
        <td>1 > 2 > 5</td>
    </tr>
    <tr>
        <td>1 > 2 > 6</td>
    </tr>
    <tr>
        <td rowspan="3">1 > 3</td>
    </tr>
    <tr>
        <td>1 > 3 > 7</td>
    </tr>
    <tr>
        <td>1 > 3 > 8</td>
    </tr>
    <tr>
        <td rowspan="3">1 > 4</td>
    </tr>
    <tr>
        <td>1 > 4 > 9</td>
    </tr>
    <tr>
        <td>1 > 4 > 10</td>
    </tr>
</table>

![alt text][1]

What I’m trying to accomplish in JQuery is this…

  1. User clicks cell “1 > 2” (which will have an ID).
  2. An item is dynamically added to the third level, but UNDER “1 > 2 > 6”.

What I could do is just add another row underneath “1 > 2” and increase the rowspan from “1 > 2”, but the new cell would then appear out of order amongst “1 > 2 > 5” and “1 > 2 > 6”.

I don’t really need the exact code to do this, just something to stop my head from spinning around this…Thanks!

  • 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-14T06:31:39+00:00Added an answer on May 14, 2026 at 6:31 am

    It seems your rowspans are a little strange, the first row of the table makes sense to have 3 cells in it, the first rowspan of 6, the second a rowspan of 2, and finally the “single cell”…

    Sadly, <tr>‘s and <td>‘s are unreliable when dealing with colspan/rowspan issues across browsers. SO1303106 shows a solution that builds up a matrix of each row/column and creates some functions to help you query it. This article inspired that solution, and shows the problem.

    Using the getTableState() function from that other article. you could do something like this:

    $("table").click(function(e) {
      var targ = $(e.target);
      var c = targ.closest('td').get(0);
      if (!c) return;
      var state = getTableState($(this).closest('table')[0]);
      var rowSpan = c.rowSpan || 1;
      // get the "bottom row" number from our clicked cell:
      var rowNum = $(c).closest('tr').get(0).rowIndex + (rowSpan - 1);
      var column = state.getRealColFromElement(c);
      // push all rowspans on the clicked td and anything to the left
      for (;column>=0; column--) {
        var cell = state.cellMatrix[rowNum][column].cell;
        cell.rowSpan = (cell.rowSpan||1)+1;
      }
      // insert a new row after the "bottom row"
      $(this).closest('table').find('tr').eq(rowNum).after(
         '<tr><td>'+$(c).text() + ' > new</td></tr>'
      );
    });
    

    And just to put it all together a jsbin preview of the finished product…

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
Can anyone help me trying to find out why this doesn't work. The brushes
Can we add multiple rows in the database table from one JSF page in
Can anyone help me figure out how I could simplify this code, without using
Can anyone tell me how I can display a status message like 12 seconds
Can you suggest some good MVC framework for perl -- one I am aware
Can I use the following across all browsers? <a href=# onclick=doSomething()>Click here.</a> Is this
Can anyone tell me what's wrong with this robots.txt? http://bizup.cloudapp.net/robots.txt The following is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6

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.