Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to get height of a div after set content in it?

    Hi All,

    i have this problem.
    I generate in a js variable some code of tthis kind:

    z = '<div id="d1"><div id="d2"><div id="d3"></div><span id="s1"></span></div></div>'

    then i write: document.write(z)

    obj = document.getElementById('d3')
    obj.innerHTML = "some long html content having tags like <h1></h1><h2></h2>"


    Then I want to get the height of my 'd3' div. I use obj.offsetHeight with Firefox and it does work, but it Does Not with Internet Explorer. I looked at so many forums and they all say that offsetHeight do find the height, but it's not working in my case. Any ideas why?

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    use DOM methods to create/append new elements instead of non-standard innerHTML method
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh

    I've changed this line:
    obj.innerHTML = "some long html content having tags like <h1></h1><h2></h2>"
    with:
    content = "some long html content having tags like <h1></h1><h2></h2>"
    var txt = document.createTextNode(content);
    obj.appendChild(txt);


    and then again tried obj.offsetHeight and it still was not working on Internet Explorer.

    Then I tried to add my div-s and span-s using DOM methods

    var div1 = document.createElement('div');
    div1.setAttribute('id','d1');
    document.body.appendChild(div1);
    var div2 = document.createElement('div');
    div2.setAttribute('id','d2');
    document.getElementById('d1').appendChild(div2);

    var div3 = document.createElement('div');
    div3.setAttribute('id','d3');
    document.getElementById("d2").appendChild(div3);

    var span1 = document.createElement('div');
    span1.setAttribute('id','s1');
    document.getElementById("d2").appendChild(span1);


    Not working again. Am I doing some mistake?

    Another thing ... all the sourse code in it's original form resulted working when it's just written in the HTML file, but if I put my divs & span in table cell <td> - it stops working..i mean it stops showing me the offsetHeight in internet Explorer. Why?
    Help me. Thanks


  •  

    Posting Permissions

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