For examples sake Lets assume you are out putting your html via a php loop (if not then you can simply loop though the elems assigning a class) same principle applies.
PHP example outputting html
<?php foreach($array as $k => $v): ?>
<?php if($k % (4) == 0) $class++; ?>
<div class="row-num-<?php echo $class ?>">
// div content variable height
</div>
<?php endforeach; ?>
jQuery Setting Equal Height per row using your existing code
var totalFrames = $('div[class*=row-num-]').length;
for ( var i = 1, l = totalFrames; i < l; i++ ) {
var heights = $(".row-num-"+i).map(function() {
return $(this).height();
}).get(),
maxHeight = Math.max.apply(null, heights);
$(".row-num-"+i).height(maxHeight);
}
This assumes your row is 4 elems wide. You can set this or dynamically calc it depending on your use. In the jQuery we loop through all elems with a class like row-num-
then we target each one setting the height. These will have the same class every four elems. It continues until the current count of this class name has been reached.
DEMO https://jsfiddle.net/DTcHh/18026/