[ka-Map-users] Determine div width

Stephen Woodbridge woodbri at swoodbridge.com
Sat Feb 24 18:58:11 EST 2007


Check out jQuery, it is an extremely lightweight but powerful javascript 
library and it is great at manipulating the DOM and getting info about 
elements and setting attributes and css stuff dynamically.

http://jquery.com

-Steve

Ionut Muntean wrote:
> Hi,
> 
> 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 
> application.
> 
> 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.style.visibility="hidden";
> parent.appendChild(myDiv);
> 
> ...
> 
> 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,
> 
> /IM
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users



More information about the ka-Map-users mailing list