2010-03-26 48 views
1

不确定我有以下CSS一个div容器:ATTR( '高度')jQuery中

#container { 
    position:relative; 
    overflow:hidden; 
    width:200px; 
    height:200px; 
} 

为什么会这样:

alert('height is ' + $("#container").attr('height')); 

回到那个高度是不确定的?

谢谢。

回答

4

尝试:

$("#container").height() 

这是由于在CSS的高度是和HTML标记不是实际属性。

6

您可能想要使用cssheight方法。

$('#container').css('height') 

$('#container').height(); 

取决于你正在尝试用它做。请参阅参考文档以了解差异。