Say for example I have this following HTML:
<div class="TwoColumnUnit">
<div class="col-md-6 col-xs-12 TwoColumnUnit_Left">
<div class="newsLetterDiv">
<div class="col-sm-12 col-md-12">
<div class="left_Side">
<i class="fas fas fa-route"></i>
<h3>This is about Tennis</h3>
</div>
<div class="right_Side">
<p><span>Tennis is a racket sport that is played either individually against a single opponent or between two teams of two players each. </span></p>
</div>
</div>
</div>
<div class="newsLetterDiv">
<div class="col-sm-12 col-md-12">
<div class="left_Side">
<i class="fas fas fa-basketball"></i>
<h3>This is about Basketball</h3>
</div>
<div class="right_Side">
<p><span>Basketball is a team sport in which two teams, most commonly of five players each, opposing one another on a rectangular court, compete with the primary objective of shooting a basketball through the defender's hoop, while preventing the opposing team from shooting through their own hoop.Basketball is a team sport in which two teams, most commonly of five players each, opposing one another on a rectangular court, compete with the primary objective of shooting a basketball through the defender's hoop, while preventing the opposing team from shooting through their own hoop.</span></p>
</div>
</div>
</div>
</div>
<div class="col-md-6 col-xs-12 TwoColumnUnit_Right">
<div class="newsLetterDiv">
<div class="col-sm-12 col-md-12">
<div class="left_Side">
<i class="fas fas fa-basketball"></i>
<h3>This is about Basketball</h3>
</div>
<div class="right_Side">
<p><span>Basketball is a team sport in which two teams, most commonly of five players each, opposing one another on a rectangular court, compete with the primary objective of shooting a basketball through the defender's hoop, while preventing the opposing team from shooting through their own hoop.Basketball is a team sport in which two teams, most commonly of five players each, opposing one another on a rectangular court, compete with the primary objective of shooting a basketball through the defender's hoop, while preventing the opposing team from shooting through their own hoop.</span></p>
</div>
</div>
</div>
<div class="newsLetterDiv">
<div class="col-sm-12 col-md-12">
<div class="left_Side">
<i class="fas fas fa-route"></i>
<h3>This is about Tennis</h3>
</div>
<div class="right_Side">
<p><span>Tennis is a racket sport that is played either individually against a single opponent or between two teams of two players each. </span></p>
</div>
</div>
</div>
</div>
</div>
Here is picture of how the HTML look .
I want to find the tallest height between Tennis
and Football
, and then set that tallest height, as the height for both Football
and Tennis
.
Likewise, I want to find the tallest height between Basketball
and Swimming
, and then set that tallest height as the height for both Football
and Tennis
.
I know how to find the max height using the Math.max
. But how do find the tallest height between each pair of two divs?
What I tried:
('.TwoColumnUnit').each(function() {
var pairs = [$(this).find('.TwoColumnUnit_Left'), $(this).find('.TwoColumnUnit_Right')];
pairs.forEach(function(pair) {
if (pair.length > 0) {
var boxes = pair.find('.newsLetterDiv > div');
var maxHeight = 0;
boxes.each(function() {
$(this).css('height', '');
maxHeight = Math.max(maxHeight, $(this).height());
});
boxes.css('height', maxHeight + 'px');
}
});
});
The problem with this code is that it’s finding the tallest height between all 4 divs and then applying that tallest height value as height for all 4 of the items.
But how can I find the tallest height between the first left and right div, and then between the second left and right div?