jQuery.outerHeight doesn't work when element i

2019-07-25 08:02发布

问题:

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.