Popup window working out the height
<p>I had a problem where I am position a popup <code>&lt;div&gt;</code> in the center of the window using:</p>

<pre><code>var popup = $("#popup"), popupWidth = popup.css("width").replace("px",""), popupHeight = popup.css("height").replace("px","");
    var xPosition = ($(window).width() - popupWidth) / 2;
    var yPosition = (($(window).height() - popupHeight) / 2) + $(window).scrollTop();

    if (yPosition &lt;= 0){
        yPosition = '0'; 
    } else if(yPosition &lt;= $(window).scrollTop()){
        yPosition = $(window).scrollTop();
    } else {
        yPosition = yPosition - 68; //minus top shaddow height
    }           

    if (xPosition &gt;= $('body').offset().left) {
        xPosition = xPosition;
    } else {
        xPosition = '0';
    }

    $(popup).css({
        'top': yPosition + 'px',
        'left': xPosition + 'px',
        'display' : 'block',
        'height' : 'auto'
    }).addClass("popup-open");
</code></pre>

<p>The problem I had was that on first load the height of the popup was being returned as 0 because it is hidden until after the position above has been worked out. To resolve this I set a default height via CSS and then once the popup has been displayed I overwrite this to auto. </p>

<p>The problem now is that if the popup has been closed and re-opened the height is auto. Is there a way to find the CSS height:value in the stylesheet not the inline height:auto</p>

<p><strong>Updated Code</strong>
Following Nicola answer here is the fixed code:</p>

<pre><code>var popup = $("#popup"), popupWidth = popup.css("width").replace("px",""), popupHeight = popup.css("height").replace("px","");

// Save/Get original height
if(popupHeight == "auto"){
    popupHeight = popup.data('origHeight');
} else {
    popup.data('origHeight', popupHeight);
}

var xPosition = ($(window).width() - popupWidth) / 2;
var yPosition = (($(window).height() - popupHeight) / 2) + $(window).scrollTop();
</code></pre>
