You are here: Reference > JavaScript > client-side > HTML DOM > properties > x (img)

x property (img)

Browser support:
Returns the left position of an image relative to the left side of its offsetParent element, in pixels.
For a cross-browser solution, use the offsetLeft property instead.


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Integer that returns the left position, in pixels.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the x property:
    <script type="text/javascript">
        function GetTopLeft () {
            var image = document.getElementById ("image");
            if ('x' in image) {
                var message = "The position of the image:";
                message += "\n Position x: " + image.x + "px";
                message += "\n Position y: " + image.y + "px";
                alert (message);
            else {
                alert ("Your browser doesn't support this example!");
    <img id="image" src="picture.gif" />
    <button onclick="GetTopLeft ();">Get the position of the image</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

User Contributed Comments

Post Content

Post Content