faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

53 of 60 people (88%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How to get the dimensions of an HTML element?
How do I find the width/height of a layer/positioned element?

Mar 7th, 2000 06:36
Martin Honnen,


For IMG elements you can access
  imageObject.width
  imageObject.height
for instance
  document['imageName'].width
  document['imageName'].height
even with NN3. The version 4 browsers kept that but introduced more 
capabilities for other elements.
With NN4 you can get the dimensions of positioned elements only with
  document.layerName.document.width
  document.layerName.document.height
and
  document.layerName.clip.width
  document.layerName.clip.height

IE4+ has several properties not only for positioned elements but for 
all HTML elements the main important being
  document.all.elementID.offsetWidth
  document.all.elementID.offsetHeight
  document.all.elementID.clientWidth
  document.all.elementID.clientHeight
http://msdn.microsoft.com/workshop/author/om/measuring.asp#chp_measuring
shows the difference and further properties.

NN6 following the DOM specs is rather weak in this regard as the specs 
forgot about computed dimensions. There are attempts however to 
implement 
  offsetWidth/offsetHeight
properties similar to the IE ones.