SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast nbaxley's Avatar
    Join Date
    Jan 2003
    Location
    Kansas
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Finding defined Div height

    I'm trying to detemine the height of a div in javascript. The actual height is defined in the attached stylesheet. When I query document.getElementById("ModuleHeader").style.height I get undefined. Here's a bit of the code:
    Code:
     <div id="ModuleHeader"> <img src="photobugHEAD.jpg" width="572" height="153"></div>
    The attached stylesheet contains this defintion:
    Code:
     #ModuleHeader {
     	width: 100%;
     	height: 153px;
     	position: relative;
     	top: 0px;
     	left: 0px;
     	z-index: 20;
     	text-align: left;
     	background-color: #33CCCC;
     }
    But this javascript returns undefined:
    Code:
     document.getElementById('ModuleHeader').style.height;
    How can I get that to return 153? I don't want to rely on the height of the image, which in this case happens to be the same height as the div.

    Thanks,
    Nate Baxley
    Nate Baxley
    http://www.baxleys.org - no excusses, it is what it is.

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,549
    Mentioned
    183 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    My javascript's skils are rubbish but I think i read that it needs to be offsetHeight.
    Code:
    document.getElementByID('ModuleHeader').offsetHeight;
    Perhaps someone else can confirm that this is correct.

    Paul

  3. #3
    SitePoint Enthusiast nbaxley's Avatar
    Join Date
    Jan 2003
    Location
    Kansas
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Paul,
    Thanks for the quick reply. It was right on the money!

    Nate
    Nate Baxley
    http://www.baxleys.org - no excusses, it is what it is.


Bookmarks

Posting Permissions

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