jQuery获取元素的渲染高度? [英] jQuery get the rendered height of an element?
本文介绍了jQuery获取元素的渲染高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取元素的渲染高度?
How do you get the rendered height of an element?
假设您有一个<div>
元素,其中包含一些内容.内部的内容将扩展<div>
的高度.当您未明确设置高度时,如何获得渲染的"高度.显然,我尝试过:
Let's say you have a <div>
element with some content inside. This content inside is going to stretch the height of the <div>
. How do you get the "rendered" height when you haven't explicitly set the height. Obviously, I tried:
var h = document.getElementById('someDiv').style.height;
执行此操作有技巧吗?如果有帮助,我正在使用jQuery.
Is there a trick for doing this? I am using jQuery if that helps.
推荐答案
应该是
$('#someDiv').height();
使用jQuery.这将以数字的形式检索包装集中的第一个项目的高度.
with jQuery. This retrieves the height of the first item in the wrapped set as a number.
尝试使用
.style.height
仅在您首先设置属性后才能使用.不太有用!
only works if you have set the property in the first place. Not very useful!
这篇关于jQuery获取元素的渲染高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文