I usually use this to match elements heights:
function equalHeight(group) {
tallest = 0;
group.each(function() {
thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
$(function() {
equalHeight($('.column'));
});
However, in my case I need to match elements to their nearest sibling not by class, with the following example
<div class="post">
<div class="leftCol">
<h2>This is a post headline</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volut</p>
</div>
<div class="rightCol">
<ul>
<li></li>
</ul>
</div>
</div><!--/post-->
There will be multiple (over 15) instances per page of this structure. I don’t want to match the height of “.leftCol” to the height of “.rightCol” across the board – that is I don’t want every “.leftCol” to match every “.rightCol” on the page, just within each “.post” group – match “.leftCol” height to its immediate sibling of the “.rightCol” class… any ideas?
If what you’re trying to do is to set each leftCol/rightCol pair to the taller of either one, but only within the pair and you want to do the same for all pairs, you can do it like this:
This code works as follows:
.post .leftColobject.leftColjQuery object.rightColjQuery object using.next().leftColand.rightColpair each to that max heightNote: you may be able to solve this problem with CSS alone. See CSS – Equal Height Columns?.