Reputation: 1
In my webpage, there is a div.content
container with position: absolute
. Inside the parent div (div.content
) there is a div.sub_content
.
I want to extract the .sub_content
height using JavaScript, or JQuery.
In the program I need to calculate the div.sub_content
height.
I'm using the below code:
$(document).ready(function(){
var a = $('div.content div.sub_content').height();
alert(a);
});
Upvotes: 0
Views: 45
Reputation: 16251
Use $('.content .sub_content').height();
See example with height
in css and without...
$(document).ready(function(){
var a = $('.content .sub_content').height();
var b = $('.content .sub_content_noHeight').height();
alert('sub_content: ' + a + ' sub_content_noHeight: ' + b);
});
.content{
position:absolute;
}
.sub_content{
height:150px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="content">
<div class="sub_content">
With height property in css
</div>
</div>
<div class="content">
<div class="sub_content_noHeight">
Without height property in css
</div>
</div>
Upvotes: 1