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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:59:59+00:00 2026-05-27T12:59:59+00:00

I have two tables, side by side. What I am trying to do is

  • 0

I have two tables, side by side. What I am trying to do is have each row of each table that is in the same container have the same row height per row. I have gotten that far with this.

The way it works is you have an array thay grabs the row heights of each table and uses the largest height for each row. Thats fine except as its a single array that means if there are other containers on the page they will look at the same array. I tried writting a closure function but failed. any ideas?

$(document).ready(function() {
var heights = [];
 computeTableHeights(true);
assignTableHeights();
var windowWidth = $(window).width();

$(window).resize(function() {    
  computeTableHeights(($(window).width() < windowWidth) && ($(window).width() !=   windowWidth));
windowWidth = $(window).width();
     assignTableHeights();  
})

function computeTableHeights(recordBiggestHeights) {
$("table").each(function() {
    var rowIndex = 0;
    var rows = $(this).find("tr");
    $(rows).each(function() {
      var rowHeight = $(this).css("height");
      if (heights[rowIndex] === undefined) {
        heights[rowIndex] = rowHeight;
      } else {
        var existingHeight = parseInt(heights[rowIndex]);
        var currentHeight = parseInt(rowHeight);
        if (shouldChangeHeight(recordBiggestHeights, existingHeight, currentHeight))  {         
             heights[rowIndex] = rowHeight;
        }
      }
      rowIndex++;
    }); 
  });
 }

function shouldChangeHeight(recordBiggestHeights, existingHeight, currentHeight) {
if (existingHeight == currentHeight) {
  return false;
} else if (recordBiggestHeights) {
  return  existingHeight < currentHeight;
} else {
  return  existingHeight > currentHeight;
}
}

function assignTableHeights() {
 $(".container table").each(function() {
    var rowIndex = 0;
    var rows = $(this).find("tr");
    $(rows).each(function() {
      var rowHeight = $(this).css("height");
      if (heights[rowIndex]) {
        var existingHeight = parseInt(rowHeight);
        var targetHeight = parseInt(heights[rowIndex]);         
        if (existingHeight != targetHeight) {
            $(this).css("height", heights[rowIndex]);
        }           
      }           
      rowIndex++;
    }); 
  });
  }
});
  • 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-27T13:00:00+00:00Added an answer on May 27, 2026 at 1:00 pm

    I think I understand what you’re trying to do. If not, please elaborate a little on the requirements you’re looking for, so I can revise this answer.

    You want to treat the row heights of each container and its child tables separately. Correct me if I’m wrong

    The code below loops through each container separately, before equalizing the heights of the table rows.

    You are indeed right that storing all row heights for all tables in one array will not get you the results you need. You would need to create an array instance per container.

    In your code you read out the css for the height of the row. Once you set the height in the css, this property will stay the same. I believe in your use-case you need the height of the row as the browser has calculated it (jquery offers methods for this purpose).

    Therefore, on resizing, the css property should be cleared, before setting it again to the greatest calculated height.

    function resizeHandler() {
        // Treat each container separately
        $(".container").each(function(i, container) {
            // Stores the highest rowheight for all tables in this container, per row
            var aRowHeights = [];
            // Loop through the tables
            $(container).find("table").each(function(indx, table) {
                // Loop through the rows of current table (clear their css height value)
                $(table).find("tr").css("height", "").each(function(i, tr) {
                    // If there is already a row height defined
                    if (aRowHeights[i])
                        // Replace value with height of current row if current row is higher.
                        aRowHeights[i] = Math.max(aRowHeights[i], $(tr).height());
                    else
                        // Else set it to the height of the current row
                        aRowHeights[i] = $(tr).height();
                });
            });
            // Loop through the tables in this container separately again
            $(container).find("table").each(function(i, table) {
                // Set the height of each row to the stored greatest height.
                $(table).find("tr").each(function(i, tr) {
                    $(tr).css("height", aRowHeights[i]);
                });
            });
        });
    }
    
    $(document).ready(resizeHandler);
    $(window).resize(resizeHandler);
    

    I have this fiddle: http://jsfiddle.net/k5g87/
    You can resize the result window in there.

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

Sidebar

Related Questions

I have two HTML tables which would ideally be placed side by side on
I have two tables that are joined together. A has many B Normally you
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables say, t1 and t2 that have t1.t1_id and t2.t2_id as
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
As per https://stackoverflow.com/questions/3264227/relations-with-multiple-keys-in-doctrine-1-2 , I have two tables which (as I can't get it
I have two tables on my page and they appear side-by-side. The first one
I have two tables which I would like to place side-by-side exactly as they
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT
I have combined two different tables together, one side is named DynDom and 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.