Can I get the height of a div that can grow depending of its content?

Discussion in 'JavaScript' started by +:::Spider25:::+, Aug 19, 2006.

  1. #1
    Hey guys,
    I see this problem a kind of difficult to be solved.
    I have a Div that can grow with comments that the posters add, I have to know what is the height of this div (ex. 120px or 500px.) this will be when the after the grow action of course.
    I need that data pals.

    Thanxs a lot
    ;)
     
    +:::Spider25:::+, Aug 19, 2006 IP
  2. Neoto

    Neoto Active Member

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #2
    Hi,

    I think it's impossible to say what the height will be before adding comments. But you can always check the current height from scrollHeight and try to predict from that.

    To get the current height, use something like this:

    var height = document.getElementById("id_of_the_element_to_check").scrollHeight;
    Code (markup):
    Neoto
     
    Neoto, Aug 20, 2006 IP
  3. +:::Spider25:::+

    +:::Spider25:::+ Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok I will try...
    Thanks
     
    +:::Spider25:::+, Sep 5, 2006 IP
  4. extremejava

    extremejava Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes the given solution works. Reached this topic from Google. Sorry for re-bouncing the topic.
     
    extremejava, Jan 20, 2012 IP
  5. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #5
    try .offestHeight

    
    var height = document.getElementById("the_div").offsetHeight;
    
    Code (markup):
     
    JohnnySchultz, Jan 24, 2012 IP
  6. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #6
    And another DP expert regurgitates a 6 year old thread.
     
    mmerlinn, Jan 24, 2012 IP