daniel-w
2/4/2015 - 6:42 PM

Set all selected elements to the same height.

Set all selected elements to the same height.

/* ========================================================================
* make product col-headers the same height
* ======================================================================== */
var equalHeights = [ ".col-header" ];

$.each( equalHeights, function( i, element ) {
	if (element.length) {
		// Get an array of all element heights
		var elementHeights = $(element).map(function() {
			return $(this).height();
		}).get();

		// Math.max takes a variable number of arguments
		// `apply` is equivalent to passing each height as an argument
		var maxHeight = Math.max.apply(null, elementHeights);

		// Set each height to the max height
		$(element).css('min-height', maxHeight);
	}
});
/**
* set all selected elements to the same height
*/

// declare function

function elementHeight(element) {
  var maxHeight = 0;

  jQuery(element).height('auto');

  jQuery(element).each(function(){
    if (jQuery(this).height() > maxHeight) { maxHeight = jQuery(this).height(); }
  });

  jQuery(element).height(maxHeight);
}

// call function

var elements = ['.flex-caption', '.page-recipe-content'];

jQuery.each( elements, function( i, val ) {
   elementHeight(val)
});