jlittlejohn
3/25/2014 - 3:37 PM

JS: Equalize Heights of an Array of Elements

JS: Equalize Heights of an Array of Elements

/*
Loop over all items in a selection
Set tallest item to maxHeight variable
Set height of all elements to maxHeight variable
*/

(function( $ ){
  $.fn.equalizeHeights = function() {
    var maxHeight = 0;
    var el = $(this);

    $(el).each(function(){ 
      if($(this).height() > maxHeight) { maxHeight = $(this).height(); } 
    }); 

    $(el).height(maxHeight);
    
    return this;
  }; 
})( jQuery );