offsetHeight property
Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, scrollBar, and the border, but does not include the margin.
The clientHeight property is similar to the offsetHeight property, but it returns the height including only the padding.
- If you need the total height of an element's contents, use the scrollHeight property. It returns the height of the contents with the padding, but without the scrollBar, border and the margin. In Opera, the scrollbar is also included.
- Another way to get the height of an object is to use the getBoundingClientRect method. It returns the bounding rectangle of the object without the margin.
Note that the offsetHeight property is special for the html element.
For further details, please see the page for the clientHeight property.
- It returns the height of the browser's client area without the horizontal scrollbar in Internet Explorer like the clientHeight property of the html element.
- In Firefox, Opera, Google Chrome and Safari, it returns the total height of the document.
- If you need a cross-browser solution to get the total size of the document, use the scrollWidth and scrollHeight properties of the html element.
- If you need the size of the browser's client area, use the clientWidth and clientHeight properties of the html element.
For further details, please see the page for the clientHeight property.
- To get the width of the document or an element in the document, use the clientWidth, offsetWidth or the scrollWidth property.
- Or, if you need the position of an element, you can use the offsetLeft, offsetTop properties and the getBoundingClientRect method.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read-only.
Possible values:
Integer that returns the height, in pixels.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the offsetHeight property:
|
||||
<head> <style> #container { width: 350px; height: 150px; margin: 10px; border: 2px solid red; padding: 15px; } </style> <script type="text/javascript"> function GetContainerSize () { var container = document.getElementById ("container"); var message = "The height with padding: " + container.clientHeight + "px.\n"; message += "The height with padding and border: " + container.offsetHeight + "px.\n"; message += "The width width padding: " + container.clientWidth + "px.\n"; message += "The width with padding and border: " + container.offsetWidth + "px.\n"; alert (message); } </script> </head> <body> <div id="container"> The width of this element is 350px<br /> The height of this element is 150px<br /> Furthermore, the element has the following style definitions:<br /> margin: 10px; border: 2px solid red; padding: 15px; </div> <button onclick="GetContainerSize ();">Get the size of the container!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
a, abbr, acronym, address, applet, area, b, bdo, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, listing, map, marquee, menu, nobr, noframes, noscript, object, ol, optgroup, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, wbr, xmp
Related pages:
External links:
User Contributed Comments