1<p>Click in the div element below to get the x (horizontal) and y (vertical) coordinates of the mouse pointer, when it is clicked.</p>
2
3<div onclick="showCoords(event)"><p id="demo"></p></div>
4
5<p><strong>Tip:</strong> Try to click different places in the div.</p>
6
7<script>
8function showCoords(event) {
9 var cX = event.clientX;
10 var sX = event.screenX;
11 var cY = event.clientY;
12 var sY = event.screenY;
13 var coords1 = "client - X: " + cX + ", Y coords: " + cY;
14 var coords2 = "screen - X: " + sX + ", Y coords: " + sY;
15 document.getElementById("demo").innerHTML = coords1 + "<br>" + coords2;
16}
17</script>