Getting the calculated height of a hidden div

I am trying to calculate the calculated div height display:noneusing this function:

function getComputedHeight(theElt){
    if(navigator.appName=='Microsoft Internet Explorer'){
        tmphght = document.getElementById(theElt).offsetHeight;
    }
    else{
        docObj = document.getElementById(theElt);
        var tmphght1 = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
        tmphght = tmphght1.split('px');
        tmphght = tmphght[0];
    }
    return tmphght;
}

This is my html

<a href="javascript:;" onclick="showme('<?php echo 'mydiv765_'.$userid[$i];?>')">View</a>

and a function called

function showme(objid)
{
    var h=getComputedHeight(objid);
    alert(h);   
}

The function returns: auto.

Please, how can I fix this? Is there a better way to achieve the same effect?

+3
source share
1 answer

Try it?

function getComputedHeight(obj){

    var originalDisplay = obj.style.display; 

    if (originalDisplay == "none") {
       obj.style.filter = "alpha(opacity=1)";
       obj.style.opacity = 0.01;
    }

    height = obj.offsetHeight;

    if (originalDisplay == "none") {
        obj.style.display = originalDisplay; 
        obj.style.filter = "alpha(opacity=100)"; // IE
        obj.style.opacity = 1; // Firefox, etc..
    }
    return height;
}

Changed from Hidden Div Height?

+1
source

All Articles