

The GetCoordinates function uses the window.event method to find the coordinates of the mouse when it is clicked.
#DISPLAY MOUSE COORDINATES JAVASCRIPT CODE#
Add the code to display the screenX and screenY and the pageX and pageY coordinates when the mouse is clicked ( Script 4.12). The following code is in the page header.Enter the code to add the jQuery library and an element and two elements to the page ( Script 4.11).Let’s understand both these ways with the below example.

Tracking Mouse Position Using PageX, PageY, and clientX, clientY in JavaScript. If you want to track mouse position based on the screen’s visible area, use clientX and clientY. We'll use the example screenxy.html from the code for the book here. JavaScript Code is given below, clientX and clientY property returns the horizontal and vertical coordinates of the mouse cursor which are then displayed inside. If you want to track mouse positions relative to the size of the webpage, use pageX and pageY.

