[Javascript] Get HTML element size

Laurent Muchacho Laurent.Muchacho at london.virgin.net
Tue Mar 8 04:28:20 CST 2005

Hi Simon,

I will recommend not to use inline style as IE will behave strangely (from
my experiences) and not always return the value.
The properties you are looking for are :

width = document.getElementById('mydiv').offsetWidth
height = document.getElementById('mydiv').offsetHeight

Remember that if you don't define the width to a div it will expand to 100%
of the width of the page.


-----Original Message-----
From: Simone Fumagalli [mailto:simone at tomato.it]
Sent: 08 March 2005 09:41
To: javascript at LaTech.edu
Subject: [Javascript] Get HTML element size

Ciao javascript,

  How do I get the width and the height of a element in my page ?

  Suppose I have this HTML:

       <div id="mydiv">
           <p>Hello people !!</p>

  with this JS code :

       my_element = getElementById("mydiv");
       alert (my_element.style.width)

  I get an empty string :-(

Suggestions ?

Simone - simone at tomato.it

Javascript mailing list
Javascript at LaTech.edu

More information about the Javascript mailing list