3

Maybe it is a stupid question, but I'd like to know if there is a "power" function that get to me the real height of a div, counting also the "display:none;" height for each element on it.

Is it just a dream?

markzzz
  • 47,390
  • 120
  • 299
  • 507
  • 4
    *"...counting also the "display:none;" height for each element on it."* `display: none` elements have no height. `visibility: hidden` ones do, but not `display: none` ones. *(Edit: And yet, according to [the question pointed out below](http://stackoverflow.com/questions/3632120/jquery-height-width-and-displaynone), jQuery handles that)* – T.J. Crowder Jan 17 '13 at 11:58
  • "display: none;" means it's not displayed hence there's no height or width. You will have to show all children inside the `
    ` and then check the height.
    – Shadow The GPT Wizard Jan 17 '13 at 11:59
  • 1
    http://stackoverflow.com/questions/3632120/jquery-height-width-and-displaynone – Andrew Cheong Jan 17 '13 at 12:00
  • you can get the height of the existing elements in the dom. – Jai Jan 17 '13 at 12:06

1 Answers1

4

I'd say that the height you're asking for is less "real" than than actual display height. You have a few options:

  1. Use visibility: hidden instead
  2. Display all of the div's descendants, get the height, and hide them immediately
  3. If number 2 doesn't work (elements are visible for too long possibly) clone the div, make it offscreen (position: fixed; top: 100% should do) and try #2 on that div.

http://jsfiddle.net/jrrdp/1/

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405