Javascript DOM MouseEvent pageY Property

Introduction

Output the coordinates of the mouse pointer when the mouse button is clicked on an element:

View in separate window

<!DOCTYPE html>
<html>
<body>

<h2 onclick="showCoords(event)">Click this heading to get the x 
and y coordinates of the mouse pointer when it was clicked.</h2>
<p id="demo"></p>
<script>
function showCoords(event) {//from   w w w.j a v  a2  s .com
  var x = event.pageX;
  var y = event.pageY;
  var coords = "X coords: " + x + ", Y coords: " + y;
  document.getElementById("demo").innerHTML = coords;
}
</script>

</body>
</html>

The pageY property returns the vertical coordinate to the document of the mouse pointer when a mouse event was triggered.

The document is the web page.

This property is read-only.

This property is non-standard, but works in most major browsers.

The pageY property returns a Number representing the vertical coordinate of the mouse pointer, in pixels.




PreviousNext

Related