Getting height or position of a DIV

Results 1 to 2 of 2

Thread: Getting height or position of a DIV

  1. #1
    Join Date
    Dec 1969

    Default Getting height or position of a DIV

    Does anyone know how to retrieve the height or position of a DIV with Javascript?<BR><BR>It appears that once you have set either of these attributes programatically, you can retrieve them no problem. But if you try to retrieve the initial values, you just get an empty string back.<BR><BR>For example<BR><BR>// css class<BR>.test<BR>{<BR> position: absolute;<BR> height: 200px;<BR> top: 200px; <BR>}<BR><BR>// using javascript (assume div&#039;s ID is "myDiv"<BR>var obj = document.getElementById("myDiv");<BR>alert(obj.sty le.height); // returns ""<BR>alert(; // returns ""<BR><BR> = 100;<BR>alert(; // returns "100px"<BR><BR>Does anyone know why this is? How can I get the values without first settings them programatically? I need to get the values that were defined in the CSS class.<BR><BR>Any suggestions would be appreciated.<BR>Thanks<BR>-Steve

  2. #2
    Join Date
    Dec 1969

    Default RE: Getting height or position of a DIV

    There are .offsetHeight and .offsetTop etc parameters that are available in most modern browsers (Google for exact syntax, and compatibility).<BR><BR>But they&#039;re not exactly the same in all browsers. The latest version of Opera seems to report them relative to the top-left, whereas other browsers report them relative to their parents. Strange, but usable.<BR><BR>Craig.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts