jQuery 获取元素的渲染高度? [英] jQuery get the rendered height of an element?
本文介绍了jQuery 获取元素的渲染高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取元素的渲染高度?
假设您有一个
元素,其中包含一些内容.里面的这个内容会拉伸
的高度.当您没有明确设置高度时,如何获得渲染"高度.显然,我试过了:var h = document.getElementById('someDiv').style.height;
这样做有技巧吗?如果有帮助,我正在使用 jQuery.
解决方案 应该是
$('#someDiv').height();
使用 jQuery.这将检索包装集中第一个项目的高度作为数字.
尝试使用
.style.height
仅在您首先设置属性时才有效.不是很有用!
How do you get the rendered height of an element?
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;
Is there a trick for doing this? I am using jQuery if that helps.
解决方案 It should just be
$('#someDiv').height();
with jQuery. This retrieves the height of the first item in the wrapped set as a number.
Trying to use
.style.height
only works if you have set the property in the first place. Not very useful!
这篇关于jQuery 获取元素的渲染高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文