Closed Thread Icon

Topic awaiting preservation: height of a div after changing innerHTML (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=27375" title="Pages that link to Topic awaiting preservation: height of a div after changing innerHTML (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: height of a div after changing innerHTML <span class="small">(Page 1 of 1)</span>\

 
macfurax
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jan 2006

posted posted 01-23-2006 17:00

Hello,

I'm trying DHTML for few days, I try to dinamically create div elements and update there contents using javascript innerHTML properties.
I realize that the height property of the elmements is not updated according to the new content (bigger or smaller). Neither style height property neither offsetHeight, or clientHeight.

Is there a way to force the browser to update these values ?

Thanks

Constant

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-23-2006 17:44

Hm... they style propery probably won't ever change... have you tried to set overflow:visible ?
And is the div actually changing it's height, or is it it fixed at whatever you defined before?

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-23-2006 17:47

Alhtough I'm sure there are ways to do this with javacript, it seems to me that the easiest way to do this is to not set the height of the div. If you don't set the height of a div, it will expand to fit whatever is in it.

macfurax
Obsessive-Compulsive (I) Inmate

From:
Insane since: Jan 2006

posted posted 01-23-2006 18:20

I got a solution elsewhere on Internet (http://www.daniweb.com/techtalkforums/thread28365.html)

I did the following create the div (and set id, visibility, absolute, width and top):

var elDiv = ne.createDIV();

elDiv.id = ne.id;

elDiv.style.visibility = 'visible';
elDiv.style.position = 'absolute';
elDiv.style.width = this.contObj.style.width;
elDiv.style.top = this.belowParkingTop +'px';

After I change the content using innerHTML, and when I need to get the height first change the height to 'auto' and then read the object offsetHeight.

obj.style.height="auto";
var dimH = obj.offsetHeight + 10;

It's working under Safari 2.0.3 and Firefox 1.5 for Mac. I will test on IE.

Hope it can help.

Constant

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 01-27-2006 23:59
quote:

macfurax said:
Hope it can help.



yep, that will help me at least. I am going to have to do something similar with a site.

Thanks.

Later,

C:\

« BackwardsOnwards »

Show Forum Drop Down Menu