getting height of a div tag default set to auto..

Discussion in 'JavaScript' started by LOD, Aug 27, 2009.

  1. #1
    hi
    i want my sidebar to be as long as my mainContent. so i want to find the height of my mainContent which is a div tag and has only width fixed to 600px. the height of this div can be as long as the text goes. so i want a javascript code that can find out this mainConten divs height. i tried using

    document.getElementByID("mainContent").style.height

    but it shows nothing... i heard somewhere that to get the height by javascript u must set the height by CSS. now i dont want my mainContent to have fixed height.. so what can i do now..

    can someone give me a code which will tell me the current height of the mainContent without requiring the height to be set first??

    thanks in Advance
     
    LOD, Aug 27, 2009 IP
  2. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    here you go:

    var h = document.getElementById('mydiv').offsetHeight;
     
    NoamBarz, Aug 28, 2009 IP
  3. LOD

    LOD Member

    Messages:
    319
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #3
    thanks mate... u r a lifesaver...
     
    LOD, Aug 28, 2009 IP