Reputation: 101
I have two div's.The height of first div changes with the height of second div.But code seems to have some trouble.My code is below. For example,
<div id="profile1">akdsfkj</div>
<div id="schedules1" style="min-height:150px;"></div>
<script>
document.getElementById('profile1').style.height=$('#schedules1').height();
</script>
Thanks in advance
Upvotes: 0
Views: 50
Reputation: 1075895
The height
property on the DOM style
object requires units, but jQuery's height()
method just returns a number (of pixels). So:
document.getElementById('profile1').style.height=$('#schedules1').height() + "px";
// Change ----------------------------------------------------------------^^^^^^^
But note that the (It's fixed in the question now.)style
attribute on your schedules1
element is invalid, you've used min:height:150px
rather than min-height:150px
.
Also, it's a bit odd to mix jQuery and straight DOM code in this way. Using all jQuery:
$('#profile1').css("height", $('#schedules1').height());
Upvotes: 1
Reputation: 28728
This works (jsfiddle):
HTML (change min:height
to min-height
):
<div id="profile1">akdsfkj</div>
<div id="schedules1" style="min-height:150px;"></div>
JavaScript (use jQuery to set the height
):
$('#profile1').height($('#schedules1').height());
Upvotes: 0
Reputation: 20428
By using Jquery we can do this..
var fheight=$('#profile1').height();
$('#schedules1').css('height',fheight);
Upvotes: 0