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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:44:25+00:00 2026-06-08T13:44:25+00:00

I want to set equal height for divs with jQuery. All the divs may

  • 0

I want to set equal height for divs with jQuery.
All the divs may have different amount of content and different default height. Here is a sample of my html layout:

<div class="container">
    <div class="column">This is<br />the highest<br />column</div>
    <div class="column">One line</div>
    <div class="column">Two<br />lines</div>
</div>
<div class="container">
    <div class="column">One line</div>
    <div class="column">Two<br>lines</div>
    <div class="column">One line</div>
</div>

I’m setting the height with the next jQuery function:

$(document).ready(function(){

    var highestBox = 0;
        $('.container .column').each(function(){  
                if($(this).height() > highestBox){  
                highestBox = $(this).height();  
        }
    });    
    $('.container .column').height(highestBox);

});

This works fine but not in my case because I want all the ‘columns’ equal only inside one ‘container’. This means that in the first container all the boxes must be as high as the first div, but in the second one they must be equal to second column.

So question is — how should I modify my jQuery to reach this?

Thank you!

  • 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-08T13:44:29+00:00Added an answer on June 8, 2026 at 1:44 pm

    Answer to your specific question

    Your code was checking all columns within any container, what you need to do is:

    • Loop through each container
      • Get the heights of each column within that container
      • Find the highest one
      • Apply that height to every column in that container before moving on to the next one.

    Note: Try to provide an example jsfiddle of your issue, it enables us
    to more easily help you and understand the issue, you get to see the
    working solution straight away and it encourages quicker responses.

    Quick (Rough) Example

    $(document).ready(function(){
    
        // Select and loop the container element of the elements you want to equalise
        $('.container').each(function(){  
          
          // Cache the highest
          var highestBox = 0;
          
          // Select and loop the elements you want to equalise
          $('.column', this).each(function(){
            
            // If this box is higher than the cached highest then store it
            if($(this).height() > highestBox) {
              highestBox = $(this).height(); 
            }
          
          });  
                
          // Set the height of all those children to whichever was highest 
          $('.column',this).height(highestBox);
                        
        }); 
    
    });
    .container { border 1px solid red; }
    .column { border: 1px solid blue; float:left; width: 30%; text-align:center; }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    
    <div class="container">
        <div class="column">This is<br />the highest<br />column</div>
        <div class="column">One line</div>
        <div class="column">Two<br />lines</div>
    </div>
    <div class="container">
        <div class="column">One line</div>
        <div class="column">Two<br>lines</div>
        <div class="column">One line</div>
    </div>

    Library!

    Here’s a library i found that looks promising if you want some more
    clever equalisation controls

    http://brm.io/jquery-match-height-demo/


    Addressing @Mem’s question

    Question: Will $(document).ready() work if you have images that need to load which in turn modify the heights of the containers?

    Equalising heights after image load

    If you are loading images, you will find that this solution doesn’t always work. This is because document.ready is fired at the earliest possible time, which means it does not wait for external resources to be loaded in (such as images).

    When your images finally load, they may distort the heights of their containers after the equalisation script has run, causing it too appear not too work.

    Solving equalising heights with images

    1. Bind to image loading events

    This is the best solution (at the time of writing) and involves binding to the img.load event. All you have to do is get a count of how many img’s there are $('img').length and then for each load, -1 from that count until you hit zero, then fire the equaliser.

    The caveat here is load may not fire in all browsers if the image is in the cache. Look around google/github, there should be a solution script out there. At the time of writing i found waitForImages from Alexander Dickson (untested, this is not an endorsement).

    1. Another more reliable solution is the window.load event. This should generally always work. However, if you check the docs out, you’ll notice this event fires after ALL external resources are loaded. This means if your images are loaded but there’s some javascript waiting to download it won’t fire until that completes.

    If you load the majority of your externals asyncronously and are clever with minimising, compressing and spreading the load you probably wont have any issues with this method, however a suddenly slow CDN (happens all the time) could cause issues.

    In both cases, you could take a dumb approach and apply fallback timers. Have the equalise script run automatically after a set few seconds just in case the event doesn’t fire or something is slow out of your control. It’s not fool proof, but in reality you’ll satisfy 99% of your visitors with this fallback if you tune the timer correctly.

    Years later this is still getting upvotes, with flexbox widely supported these days you may want to consider just plain CSS for this, unless there’s a specific reason you are using JS for it

    .container {
      display: flex;
      border: 2px dashed red;
      margin: 10px 0;
    }
    
    .container > .column { 
     padding: 10px;
    }
    
    .container.fill-width {
      justify-content: stretch;
    }
    
    .container.fill-width>.column {
      flex-grow: 1
    }
    
    .container>.column:nth-child(1) {
      background: yellow;
    }
    
    .container>.column:nth-child(2) {
      background: blue;
    }
    
    .container>.column:nth-child(3) {
      background: green;
    }
    <div class="container">
      <div class="column">Some<br>text</div>
      <div class="column">Some<br>more<br>text<br>here</div>
      <div class="column">One line</div>
    </div>
    <div class="container">
      <div class="column">Some<br>more<br>even<br>longer<br>text<br>here</div>
      <div class="column">Some<br>text</div>
      <div class="column">One line</div>
    </div>
    <div class="container fill-width">
      <div class="column">Some<br>more<br>text<br>here</div>
      <div class="column">Some<br>text</div>
      <div class="column">One line</div>
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to set equal height in div which have class name modelCode so
So I have a double set to equal 1234, I want to move a
I have a site . I want to make 3 vertical divs with equal
I want to set two properties equal to each other in one object. Here's
I have a list of content items, each with a set width but different
I want to set the listview datacontext equal to an observable collection so that
My question is : I have an EditText and I want set a margin
i have a problem, i want set text of a UILabel or UItextView or
i have a multiple marker Google map, it works fine but i want set
I want to make a WPF TextBox have a DarkBlue border and thickness equal

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.