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);
});
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.