[ka-Map-users] Determine div width

Ionut Muntean ionut at muntean.ro
Sat Feb 24 18:39:26 EST 2007


I know this is off-topic but, please, help!

Is there any possibility to determine the width of a DIV element at 
runtime, depending on the div's innerHTML? The html content is changing 
and I have to resize the div according to the html content. I'm trying 
to build an infowindow with shadow and round corners for my kaMap 

Done the following:


var parent = document.createElement('div');
parent.width = screen.width;
parent.height = screen.height;
parent.left = -screen.width;
parent.top = -screen.height;
parent.style.visibility = "hidden";

var myDiv = document.createElement('div');
myDiv.style.width = "auto";
myDiv.style.height = "auto";


myDiv.innerHTML = "This is a test!<br>Second line.";

var x = Math.max(myDiv.offsetWidth, 100);
var y = Math.max(myDiv.offsetHeigth, 10);

// do something with x and y

myDiv.style.visibility = "visible";


The problem is that in FireFox everything works ok, but in IE6-7 the 
reported offsetWidth is the width of the "parent" element.

How can this be done for both browsers?

Thank you all,


More information about the ka-Map-users mailing list