簡體   English   中英

獲取父DIV具有絕對位置的DIV的高度(JQuery)

[英]Get the height of a DIV where the parent DIV has position absolute (JQuery)

在我的網頁中,有一個div.content容器,其position: absolute 在父div( div.content )內部有一個div.sub_content 我想使用JavaScript或JQuery提取.sub_content高度。

在程序中,我需要計算div.sub_content height

我正在使用以下代碼:

$(document).ready(function(){
    var a = $('div.content div.sub_content').height();
    alert(a);
});

使用$('.content .sub_content').height();

參見示例, height為css,不包含...

 $(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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM