2009-11-13 74 views
0

我有一個div,我想獲得div的高度。如何在IE中使用jquery獲得div的高度

$('.graph_container').css('height') 

和css是

.graph_container { 
    width:100%; 
    float:left; 
    border:1px solid #CCCCCC; 
    margin-top:1em; 
    position:relative; 
} 

由於高度沒有提到,在IE中把它交給 '自動'。我怎樣才能得到活的高度。

我很感謝您的建議。

回答

3
$('.graph_container').height() 

它返回一個數字。

0

要計算任何元素或窗口或文檔的高度,我們可以使用jQuery的「height()」方法。

$(document).ready(function(){ 
$("p").append($("p").height()+" px"); 
$("div.divContainer").append($("div.divContainer").height()+" px"); 
$("div.document").append($(document).height()+" px"); 
$("div.window").append($(window).height()+" px");   
}); 

<div class="document">Height of this document is: </div> 
<div class="window">Height of this window is: </div> 
<div class="divContainer">Height of this div container is: </div> 
<p>Height of this paragraph is: </p>