0

Just a little edit, in case it helps anyone out who happens to stumble upon this. The answer given worked perfectly until I added some images. The images I added have no set width or height and have max-width 100% css applied to them so they scale within a fluid grid. Problem seems to be chrome was not adding the height of the images to the total column heights so the columns were being rendered to short ( minus the images height )

Changing the line of code:

$(document).ready(function(){

to

$(window).load(function() {

Seems to fix the problem.

------------ original question ----------------

I'm trying to implement this jquery code I came across here; I can't for the life of me figure out how to get it working though.

I've included a link to jQuery in my document and tried various options but I can't get it working.

My page is a html5 2 column layout, with the 2 columns set with % widths and floated. The content of left column is long so I would like them to be equal.

I'm guessing I need to add the class unevenheights to a div. I've added it to each column and tried it on the wrapper div with no luck.

I tried copying to first section to a seperate file and saving as a .js, then linking to that and using the $('div.unevenheights').setAllToMaxHeight() part within <script> tags in the page head but no joy.

Could someone please explain in beginner terms how I should implement it?

$.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}

// usage: $('div.unevenheights').setAllToMaxHeight()

1 Answer 1

1

a) Wrap your call in a $(document).ready() callback like this:

$(document).ready(function(){
    $.fn.setAllToMaxHeight = function(){
        return this.height(Math.max.apply(this, $.map(this, function(e){
            return $(e).height()
        })));
    };

    $('div.unevenheights').setAllToMaxHeight();
});

Working Fiddle

b) In case that doesn't work out, please post your html and js here or — even better — as a jsFiddle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.