Skip to content

Instantly share code, notes, and snippets.

@k4200
Created July 11, 2012 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4200/3088139 to your computer and use it in GitHub Desktop.
Save k4200/3088139 to your computer and use it in GitHub Desktop.
Calculate height (or width etc.) of a hidden element
/**
* Based on the following discussion:
* http://stackoverflow.com/questions/2345784/jquery-get-height-of-hidden-element-in-jquery
* @param jQuery $elem jQuery object
*/
function getHeightOfHiddenElem($elem) {
$clone = $elem.clone();
$clone.css({'position':'absolute','visibility':'hidden','display':'block'});
$('body').append($clone)
var height = $clone.height();
$clone.remove();
return height;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment