jQuery.outerHeight doesn't work when element is hidden?

不打扰是莪最后的温柔 提交于 2019-12-24 11:07:29

问题


I'm trying to find out the outer height of a element (including padding) and it doesn't seem to work.

I always get 0. Is it because the element is hidden?

The element is contained inside a absolute-positioned element with "auto" height, but I don't think that should be a issue, because the element is relative...


回答1:


a hidden element has an outer height,

<div id="aaa" style="visibility:hidden">aaa</div>
<div id="bbb" style="visibility:hidden"></div>

alert($("#aaa").outerHeight());// returns 20

alert($("#bbb").outerHeight()); //returns 0

please add your html code for a more complete answer




回答2:


An element with hidden with a display: none; does not register height or width, but an element with visibility: hidden; does, but it also must be attached to the body or one of its children elements.



来源:https://stackoverflow.com/questions/7131995/jquery-outerheight-doesnt-work-when-element-is-hidden

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!