offsetHeight and offsetWidth not working in IE and Mozilla both

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    offsetHeight and offsetWidth not working in IE and Mozilla both

    HTML code

    Code:
    <div id="dtls_DIV" style="background-color:#CCCCCC;border-style:solid;border-width:1px;border-color:#000000;display:none;position:absolute;height:180px;width:230px;overflow:auto">
        <table id="dtls_TAB" border=0 cellpadding="2" cellspacing="2" width=100%>
            <tr>
                <td nowrap id="dtls_TD" class="searchbgcolor" style="background-color:#DDEEEE">Not Available<BR/></td>
                <td align="right" valign="top"><input type=button class=button value="X" onclick="document.getElementById('dtls_DIV').style.display='none';" title="close the window"/></td>
            </tr>
        </table>
    </div>
    Javascript Code
    Code:
    function showList(value,obj){
        alert(value);
        var pos = findPos(obj);
        var left = pos[0], top = pos[1];
        var div_ref = document.getElementById('dtls_DIV');
        if(value!='') document.getElementById('dtls_TD').innerHTML = value;
        else document.getElementById('dtls_TD').innerHTML = 'Not Available</BR>';
        div_ref.style.left = left+'px';
        div_ref.style.top = top+'px';
        var dtls_TAB = document.getElementById('dtls_TAB');
        div_ref.style.height = (dtls_TAB.offsetHeight+10)+'px';
        div_ref.style.width = (dtls_TAB.offsetWidth+10)+'px';
        div_ref.style.display = 'block';
    }
    On first click(method call) it's not working on 2nd click(method call) it's working.
    Why it's happening .....
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    how are these two codes related? the Javascript is not triggered as far as I see.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      When onClick event fires from any element then it happens.
      Actually i thought no matter from where the method called, that's why i didn't post the calling of method ;)

      Actually what's happening ... offsetHeight and offsetWidth returns zero... :(

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        It looks like you are trying to get the offset size of an element whose style.display is 'none'.

        offsets are figured from the rendered size of an element- the space it takes up in the browser window. If the display is none, it has no offset size, or 0.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Ah..aah...I see ..Thanks for your reply ;)

          Comment

          Working...