This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

offsetLeft

Property of dom/HTMLElementdom/HTMLElement

Syntax

var result = element.offsetLeft;
element.offsetLeft = value;

Examples

This example uses the offsetLeft property to determine whether an object is in the user’s view.

<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>

View live example

Notes

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.

Syntax

Attributions