jQuery script – Equal height div

I came across a problem which I want  to set my div height equal.  This script will calculate the maximum height from the set of elements and apply max height to each div which has same class.

 

jQuery:

$.fn.sameHeights = function() {
$(this).each(function(){
var tallest = 0;
$(this).children().each(function(i){
if (tallest < $(this).height()) { tallest = $(this).height(); }
});
$(this).children().css({'height': tallest});
});
return this;
};
//* Call your function */
$(document).ready(function(){
  $('.boxes').sameHeights();
});
Share this nice post: