Retrieves the calculated left position of the object relative to the layout or coordinate parent, as specified by the offsetParent property.
Syntax
| JavaScript | |
|---|
Property values
Type: Integer
the left position, in pixels.
Remarks
You can determine the location, width, and height of an object by using a combination of the offsetLeft, offsetTop, offsetHeight, and offsetWidth properties. These numeric properties specify the physical coordinates and dimensions of the object relative to the object's offset parent.
For more information about how to access the dimension and location of objects on the page through the Dynamic HTML (DHTML) Document Object Model (DOM), see Measuring Element Dimension and Location with CSSOM in Internet Explorer 9.
Examples
This example uses the offsetLeft property to determine whether an object is in the user's view.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/offsetLeft.htm
<script type="text/javascript">
function isinView(element) {
var oparent = element.offsetParent;
var osleft = oID_1.offsetLeft;
var cleft = oparent.clientWidth;
if (osleft > cleft) {
alert("Expand the window to see the paragraph!");
}
}
</script>
...
<button onclick="isinView(this)">Click here</button>
...
<div id="oID_1" style="position: absolute; top:200px; left:1200px;">
...
</div>
See also
- a
- abbr
- acronym
- address
- applet
- area
- b
- bdo
- big
- blockQuote
- body
- br
- button
- caption
- center
- cite
- code
- col
- colGroup
- custom
- dd
- del
- dfn
- dir
- div
- dl
- dt
- em
- embed
- fieldSet
- font
- form
- frame
- hn
- hr
- i
- iframe
- 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
- ins
- kbd
- label
- legend
- li
- listing
- map
- marquee
- menu
- noBR
- object
- ol
- option
- p
- plainText
- pre
- q
- rt
- ruby
- s
- samp
- select
- small
- span
- strike
- strong
- sub
- sup
- table
- tBody
- td
- textArea
- TextRange
- tFoot
- th
- tHead
- tr
- tt
- u
- ul
- var
- xmp
- Reference
- boundingHeight
- boundingLeft
- boundingTop
- boundingWidth
Send comments about this topic to Microsoft
Build date: 11/28/2012