[This documentation is preliminary and is subject to change.]
Retrieves the width of the object including padding, but not including margin, border, or scroll bar.
Syntax
| JavaScript | |
|---|
Property values
Type: Integer
the width of the object, in pixels.
Examples
This example shows how the clientWidth property and the offsetWidth property measure document width differently. The width of the div is set to 200, and this is the value retrieved by the offsetWidth property, not the clientWidth property.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/clientWidth.htm
<DIV ID=oDiv STYLE="overflow:scroll; width:200; height:100"> . . . </DIV> <BUTTON onclick="alert(oDiv.clientWidth)">client width</BUTTON> <BUTTON onclick="alert(oDiv.offsetWidth)">offset widthY</BUTTON>
See also
- a
- address
- applet
- b
- bdo
- big
- blockQuote
- body
- button
- caption
- center
- cite
- code
- col
- colGroup
- custom
- dd
- dfn
- dir
- div
- dl
- dt
- em
- embed
- fieldSet
- form
- hn
- html
- i
- img
- input type=button
- input type=checkbox
- input type=file
- input type=image
- input type=password
- input type=radio
- input type=reset
- input type=submit
- input type=text
- isIndex
- kbd
- label
- legend
- li
- listing
- marquee
- menu
- meta
- noBR
- object
- ol
- option
- p
- plainText
- pre
- s
- samp
- script
- select
- small
- span
- strike
- strong
- sub
- sup
- table
- tBody
- td
- textArea
- tFoot
- th
- tHead
- tr
- tt
- u
- ul
- var
- xmp
- Measuring Element Dimension and Location with CSSOM in Internet Explorer 9
Build date: 3/8/2012
IE does not provide a simple way to accurately retrieve the size of a document! document.documentElement.clientWidth reports 0 (zero) in some cases, while document.body.clientWidth also reports 0 in others. In some cases clientWidth may report the width of the object minus the size of the scrollbar, even when there is no scrollbar on the screen.