layerX property (event)
Retrieves the x-coordinate of the mouse pointer relative to the top-left corner of the closest positioned ancestor element of the element that fires the event.
Use the target and srcElement properties to get the element that fires the event. A positioned element is an element whose position property is set to relative, absolute or fixed. If the mouse pointer is not inside a positioned element, then the position is relative to the top-left corner of the document.
In Internet Explorer, Opera, Google Chrome and Safari, the x property provides similar functionality.
The layerX property is rarely useful, use other event properties instead.
- To get the position relative to the top-left corner of the document, use the pageX and pageY properties.
- If you need the position of the mouse pointer relative to the top-left corner of the browser window's client area, use the clientX and clientY properties.
- To get the position relative to the top-left corner of the screen, use the screenX and screenY properties.
- Or, if you need the element that is located at a specified position, use the elementFromPoint method.
You can find the related objects in the Supported by objects section below.
This property is read-only.
Integer that represents the horizontal position of the mouse pointer, in pixels.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the layerX property:
Did you find this example helpful?
User Contributed Comments