Closed Thread Icon

Preserved Topic: hegiht of a div (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18523" title="Pages that link to Preserved Topic: hegiht of a div (Page 1 of 1)" rel="nofollow" >Preserved Topic: hegiht of a div <span class="small">(Page 1 of 1)</span>\

 
Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 11-06-2001 02:49

If i have text inside a div tag, is it then posible to find out the height of the layer?

<div style="position:absolute; height:100; width:100; overflow:hidden;">
<div id="text">
dfasdfasdfasdfasdjf asdfaølskd øalksd føalks dfølaksdøla sjdfø asdføa sdføal skdjfaølsdføalksd føads aasdfasd
asdf asdfasdflajksdløf ajsdflakj
</div></div>

the height of the text layer?

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 11-06-2001 06:46

Say you have a div called "myDiv" then these are supposed to work.

For IE:
document.all.myDiv.clientHeight
for NN4:
document.myDiv.clip.height
for NN6:
document.getElementById("myDiv").style.height

This is a good opportunity to ask this. But I have not been able to get this to work for NN6. No matter what I try I can't get the height of my divs using this method. Is this a bug or am I doing something wrong?


mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 11-06-2001 07:13

This should work in Mozilla:

if (document.getElementById("myDiv").style.height)
&nbsp;&nbsp;&nbsp;&nbsp;return(parseInt(document.getElementById("myDiv").style.height));
else
&nbsp;&nbsp;&nbsp;&nbsp;return(document.getElementById("myDiv").offsetHeight);



[yp]
Nervous Wreck (II) Inmate

From: Atlanta, GA, USA
Insane since: Nov 2001

posted posted 11-06-2001 16:13

actually, <obj>.style.height will always give you what you put in for it's style attribute -- which you already probably know.

to find out how much space an element is actually taking up, you can use these:

NN4 (abs-pos'd DIVs and LAYERS only): <obj>.document.height
IE4+ <obj>.offsetHeight
NN6/MOZ/DOM: document.defaultView.getComputedStyle(<obj> ).getPropertyValue("height")

in all these, <obj> is reference to the element, which you also must get using hacks and workarounds:

NN4: var obj = document.layers["foo"];
IE4: var obj = document.all["foo"];
IE5+, NS6, DOM: var obj = document.getElementById("foo");

hope this helps you.

like your mom, only more fun in the sack

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 11-07-2001 01:44

As stated in my example from above offsetHeight works in Mozilla, too, so there's no need for a little bit more complicated getComputedStyle() function in this case when we only need layer's height...

BTW getComputedStyle() takes two parameters, the first represent the element whose style is to be computed and the second is the pseudo-element or null if none, so correct code from [yp]'s post would be:

document.defaultView.getComputedStyle(<obj>, null).getPropertyValue("height");


[yp]
Nervous Wreck (II) Inmate

From: Atlanta, GA, USA
Insane since: Nov 2001

posted posted 11-07-2001 09:04

damn - i scanned over that line of code. sorry max. saw that you were using .style.height (which is kinda strange since, you normally either want the stated height or the actual height, not whichever one is available) but whatever.

*but* i have had problems with offsetHeight not working for abs-pos'd elements, so i think that the computedStyle() way might be better in that regard.

.peace.

like your mom, only more fun in the sack

« BackwardsOnwards »

Show Forum Drop Down Menu