如何获得元素的渲染高度? [英] How do you get the rendered height of an element?

查看:164
本文介绍了如何获得元素的渲染高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得元素的渲染高度?

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();

。这将检索包装集中第一个项目的高度作为数字。

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!

这篇关于如何获得元素的渲染高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆