View Full Version : How to get height of a div after set content in it?

05-31-2006, 03:28 PM
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?

05-31-2006, 04:06 PM
use DOM methods to create/append new elements instead of non-standard innerHTML method

06-01-2006, 10:14 AM
I've changed this line:
obj.innerHTML = "some long html content having tags like <h1></h1><h2></h2>"
content = "some long html content having tags like <h1></h1><h2></h2>"
var txt = document.createTextNode(content);

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');
var div2 = document.createElement('div');

var div3 = document.createElement('div');

var span1 = document.createElement('div');

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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum