Skip to content

Instantly share code, notes, and snippets.

@johnantoni
Created April 13, 2011 13:01
Show Gist options
  • Select an option

  • Save johnantoni/917493 to your computer and use it in GitHub Desktop.

Select an option

Save johnantoni/917493 to your computer and use it in GitHub Desktop.
setAllToMaxHeight (jquery)
$.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}
// usage: $(‘div.unevenheights’).setAllToMaxHeight()
// http://www.broken-links.com/2009/01/20/very-quick-equal-height-columns-in-jquery/
@johnantoni

Copy link
Copy Markdown
Author

or...

var highestCol = Math.max($('#element1').height(),$('#element2').height());
$('.elements').height(highestCol);

@johnantoni

Copy link
Copy Markdown
Author

$.fn.setAllToMaxHeight = function (minHeight) {
minHeight = minHeight || 0;
if (minHeight !== 0)
{ return this.height(minHeight); }
else
{ return this.height(Math.max.apply(this, $.map(this, function (e) { return $(e).height() }))); }
}

@rickydazla

Copy link
Copy Markdown

fckYEAH! Nicely noted!

@rickydazla

Copy link
Copy Markdown

NB - use the following to avoid Chrome/Safari bugs:
$(window).load(function() {
$('div.unevenheights').setAllToMaxHeight();
});

@ganar

ganar commented Nov 13, 2015

Copy link
Copy Markdown

Hi @rickydazla, @johnantoni

Any idea on how to trigger setAllToMaxHeight() on orientationchange without including the entire jquery mobile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment