Both window.getComputedStyle(element).height
and element.clientHeight
are returning the current height of the element in pixels, regardless of the value set in the CSS.
Is there any way to find out if the height was set to auto
, or other units than pixels ?
One solution that @pvnarula suggests through the page he linked is to temporarily change the contents of the element, then compare heights. A little bit hacky...
Please try:
Also check the following plugin:
http://gregpettit.ca/2012/jquery-check-if-element-has-auto-widthheight/
Update:
Based on other answers and lot of online research I came up with a mix of everything in a single function. Check out the jsfiddle here: https://jsfiddle.net/oriadam/d01ap7r6/3/
** Ghost element method explained (Previous answer):**
Greg Pettit had a pretty good answer in his blog, here is the main idea:
Cleanup
var isAutoHeight = function(element) { // make a staging area for all our work. $('body').append('');
};