Keefer
Keefer

Reputation: 2289

jQuery to set the height of a div to match the one next to it

I've got two divs (#mosaicBlog and #mosaicAside). I've got #mosaicAside's CSS set to overflow hidden and want to set #mosaicAside to always be the height of #mosaicBlog (dynamic height page to page).

I thought this would work, but it does not seem to be working. I'm thinking it may just be a syntax problem.

$(function(){
    var curHeight = parseInt($("#mosaicBlog").height());
        newHeight = Math.ceil(curHeight/189) * 189 - 7;
            alert(newHeight );
    $("#blogAside").height(newHeight);
});

Any help would be appreciated.

Upvotes: 0

Views: 480

Answers (2)

jimy
jimy

Reputation: 4908

try after loading document

$(document).ready( function() {
    var curHeight = parseInt($("#mosaicBlog").height()),
     newHeight = Math.ceil(curHeight/189) * 189 - 5;
     $("#blogAside").height(newHeight );
});

Upvotes: 0

Calum
Calum

Reputation: 5316

Use $(function(){ instead of $({

http://jsbin.com/uzera7/edit

Upvotes: 1

Related Questions