Reputation: 5044
i have 2 div's, left and right, the content in right div is setted dynamically so as its height, so i haven't specified its height in html, now what i want is the height of the left div should be equal to the right div, how to set the height of the left div as per the height of right div, using jquery, i tried
$("#leftDiv").height($("RightDiv").height());
this does not seems working, as i haven't specified the height of the right div in html. is there any other wayout, apart from using tables.
Upvotes: 5
Views: 20777
Reputation: 2700
$(function() {
if($("#RightDiv").height() > $("#leftDiv").height()){
$("#leftDiv").css("height", $("#RightDiv").height() + "px");
} else {
$("#rightDiv").css("height", $("#leftDiv").height() + "px");
}
}
Upvotes: 0
Reputation: 60438
Looks like your selector for RightDiv
is not right or you forgot to wait while the DOM is loaded.
Html
<div id="leftDiv" style="border:1px solid red">left div</div>
<div id="RightDiv" style="height:100px; border:1px solid red">right div</div>
jQuery
$(function() {
$("#leftDiv").height($("#RightDiv").height());
})
Upvotes: 2
Reputation: 1399
try
var firstHeight = $("#RightDiv").height() + 'px';
$("#leftDiv").css("height", firstHeight);
Upvotes: 0
Reputation: 5553
Try this:
$("#leftDiv").height($("#RightDiv").get(0).scrollHeight);
Upvotes: 1