I discovered something weird yesterday when working with a piece of JS code. I had a div
that was hidden (display:none
), and I was using the height of it in some calculations in JS. This was all working fine, until I added my "hidden" class (which has display:none !important
).
Suddenly the height was always 0
. There were no other changes than !important
on the display.
After some digging I've narrowed the problem down to something I find rather weird:
#b { display:none; } /* reported height is 36 */
#c { display:none !important; } /* reported height is 0 */
I've created a very basic JSFiddle to isolate this. It also uses vanilla JS to get height, which seems to work just fine / as expected.
It seems like jQuery incorrectly reports height on invisible DIVs, and that !important
behaves correctly.
Is this a bug in jQuery?