Skip to content

Instantly share code, notes, and snippets.

@321zeno
Last active December 16, 2015 13:29
Show Gist options
  • Save 321zeno/5441862 to your computer and use it in GitHub Desktop.
Save 321zeno/5441862 to your computer and use it in GitHub Desktop.
Get height of hidden element using jQuery. Credits go to http://stackoverflow.com/users/414385/hitautodestruct
jQuery(function( $ ){
$.fn.actualHeight = function(){
// find the closest visible parent and get it's hidden children
var visibleParent = this.closest(':visible').children(),
thisHeight;
// set a temporary class on the hidden parent of the element
visibleParent.addClass('temp-show');
// get the height
thisHeight = this.height();
// remove the temporary class
visibleParent.removeClass('temp-show');
return thisHeight;
};
// get the hidden div's height and show what you got
$('#height').text( $('.hidden').actualHeight() );
});
// .temp-show{position:absolute !important; visibility:hidden !important; display:block !important;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment