javascriptjqueryouterheight

JQuery outerHeight() return none-zero on hidden (display:none) element?


I think it should return 0 for display:none elements. but it doesn't, at least for 1.10.1

<div id="a" style="display:none">
    asdf
    asdfasdf<br>
    sadf
</div>

alert($('#a').outerHeight(true))

http://jsfiddle.net/pUuAz/


Solution

  • jQuery gives you the height of the element regardless to if it's displayed on the screen.

    If you want it to ignore an hidden element use the following:

    $('#a').is(':visible') ? $('#a').outerHeight(true) : 0;