This page is Ready to Use

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

y

Summary

Gets the y-coordinate of the mouse pointer, relative to the last positioned ancestor element.

Property of dom/MouseEventdom/MouseEvent

Syntax

Note: This property is read-only.

var yCoordinate = event.y;

Return Value

Returns an object of type NumberNumber

The Y coordinate of the mouse cursor.

Examples

This example displays the current mouse position in the browser’s status window.

document.body.onmousemove = function (e) { console.log('X = ' + e.x + ' Y = " + e.y); }

Notes

If the event firing element is relatively positioned, then the y-coordinate from the boundary of the element is returned. If the event firing element and all of its parent elements are not relatively positioned, then the y property returns a coordinate relative to the body element. The y property returns a coordinate relative to the body element. If the mouse or finger is outside the window at the time the event fires, this property returns -1.

Related specifications

CSSOM View
Working Draft

Attributions