【发布时间】:2013-10-10 22:33:07
【问题描述】:
我的网页中有隐藏元素,我需要获取该元素的高度。我已经尝试过使用 .clientHeight、offsetHeight、.height() 和 window.getComputedStyle,但在附加场景中没有这样的工作。有没有什么技巧可以在不添加任何插件的情况下获得高度。 fiddle
HTML
<div class="frame">
<p>some text some text some text some text</p>
</div>
jQuery
$('p').height()
【问题讨论】:
-
试试
.clientHeight而不是.clientWidth:p -
@ŠimeVidas:这是我的拼写错误,clientHeight 也不起作用
-
您可以暂时删除
display:none并添加visibility:hidden。 -
警报($('p').html().length)
-
@RobertRozas:这行不通……当实际元素高度为 20 时,它返回 39。
标签: javascript jquery