To reiterate my comments:
Resetting
curTalleston each iteration will prevent finding the tallest element. Each element in the loop will be considered the tallest becausecurTallestis reset to zero each time.You'll only need to reset the height of
divGroupifcurrent.height() > currTallest. Currently, you reset the heights upon each iteration, regardless of whethercurrTallesthas changed.cardHeights()expects a jQuery object. You are passing it a string. Either pass a jQuery object or convert the string to an object within the function.
That being said, my suggestion is to collect all heights, determine the maximum height from those values, and set all heights to the maximum height. This prevents needlessly setting heights multiple times.
Here's an example:
$(function() { cardHeights('.card'); $(window).on('resize', cardHeights('.card')); }); function cardHeights(divGroup) { /* Initialize variables */ var heights = [], $group = $(divGroup); /* Iterate through the selected elements, pushing their heights into an array */ $group.each(function() { heights.push($(this).height()); }); /* Determine the maximum height in the array */ var maxHeight = Math.max.apply(Math, heights); /* Set the height of all elements in the group to the maximum height */ $group.height(maxHeight); } div.card { background-color: #CCC; margin: 1em; padding: 1em; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class="card">Test</div> <div class="card">Test<br />Tester<br />Testing<br />Test-o-rama<br />Tallest!</div> <div class="card">Test<br />Tester</div> Edit
If, for some reason, you don't want to use an array, you can use your original method of comparing each element's height to the maximum height:
function cardHeights(divGroup) { /* Initialize variables */ var $group = $(divGroup), maxHeight=0, thisHeight=0; /* Iterate selected elements, reset maxHeight if the current height is taller */ $group.each(function() { thisHeight=$(this).height(); if (thisHeight>maxHeight) {maxHeight=thisHeight;} }); /* Set the height of all elements in the group to the maximum height */ $group.height(maxHeight); }