MouseEvent screenY Property - Javascript DOM

Javascript examples for DOM:Mouse Event

Description

The screenY property returns the vertical coordinate of the mouse pointer.

This property is read-only.

Return Value

A Number, representing the vertical coordinate of the mouse pointer, in pixels

The following code shows how to get coordinates of the mouse pointer, relative to the screen.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<h2 onclick="showCoords(event)">Click this heading</h2>

<p id="demo"></p>

<script>
function showCoords(event) {/*  w ww  .j av  a 2  s. c o  m*/
    var x = event.screenX;
    var y = event.screenY;
    var coords = "X coords: " + x + ", Y coords: " + y
    document.getElementById("demo").innerHTML = coords;
}
</script>

</body>
</html>

Related Tutorials