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

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

问题描述

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

How do you get the rendered height of an element?

假设你有一个< div> 元素里面有一些内容。这个内容将拉伸< div> 的高度。当您没有显式设置高度时,如何获得已渲染高度。显然,我试过:

Lets 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;

有办法吗?

推荐答案

应该只是

$('#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!

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

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