Click to See Complete Forum and Search --> : [RESOLVED] Returning height of div in firefox and javascript
gallarpri
04-20-2007, 01:53 PM
Hi all! Can anyone tell me what is the javascript syntax for ascertaining the height and width of a div? I have achieved it in IE (read this: http://lists.evolt.org/archive/Week-...09/122159.html) but it doesn't work in firefox. I need to know the dimensions when the onload event has fired. The div is dynamically populated with text on the server, so the height is not set at any point.
You can see it working in IE in this test page: http://www.josegallardo.net/index3.php
I have a master div ('cuerpo2col') that should have the larger height of the children divs ('colcontenido' and 'menu').
Any help would be apreciated :)
Znupi
04-20-2007, 02:21 PM
You shouldn't use IE's proprietary document.all['colcontenido'], and use the W3C-standard document.getElementsById('colcontenido');
gallarpri
04-20-2007, 02:33 PM
Thanks Znupi for answering. I have tried with document.getElementsById, but it doesn't seems to work :confused: this is the page with the code: http://www.josegallardo.net/index4.php
Thanks! :)
Znupi
04-20-2007, 04:44 PM
Try this, I don't guarantee if it works:
function jsAjuste(numColumnas) {
var masterdiv = document.getElementById("cuerpo2col");
var contentdiv = document.getElementById("colcontenido");
var menudiv = document.getElementById("menu");
var hcapa1 = contentdiv.offsetHeight;
var hcapa2 = menudiv.offsetHeight;
if ( hcapa1 > hcapa2 ) { masterdiv.style.height = (hcapa1 + 200) + "px"; }
else { masterdiv.style.height = hcapa2 + "px"; }
}
gallarpri
04-20-2007, 04:51 PM
WOW, now it works !! :D :D :D Thanks Znupi! :)
Znupi
04-20-2007, 05:03 PM
Anytime :). Semi-offtopic: what do you use the 'numColumnas' parameter for? :confused:
gallarpri
04-20-2007, 05:22 PM
:p I have 2 versions of the design of the webpage, one version in one column and another in two columns, with this variable I select the height of the correct column ^^
For example, the 2 columns design is: http://www.josegallardo.net
and the 1 column design: http://www.josegallardo.net/cv.php
cheers ^^
Jose.