...

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



jibonita
05-31-2006, 02: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?

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

jibonita
06-01-2006, 09:14 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum