Setting equal heights for div's with jQuery Setting equal heights for div's with jQuery jquery jquery

Setting equal heights for div's with jQuery


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>