MouseEvent clientX Property - Get clientX and clientY and screenX and screenY from mouse event - Javascript DOM

Javascript examples for DOM:Mouse Event

Description

MouseEvent clientX Property - Get clientX and clientY and screenX and screenY from mouse event

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div {//w w w  . j a v  a  2s  .c  o  m
    width: 500px;
    height: 300px;
    border: 1px solid black;
    text-align: center;
}
</style>
</head>
<body>

<div onclick="showCoords(event)">Move your mouse here:<p id="demo"></p></div>

<script>
function showCoords(event) {
    var cX = event.clientX;
    var sX = event.screenX;
    var cY = event.clientY;
    var sY = event.screenY;
    var coords1 = "client - X: " + cX + ", Y coords: " + cY;
    var coords2 = "screen - X: " + sX + ", Y coords: " + sY;
    document.getElementById("demo").innerHTML = coords1 + "<br>" + coords2;
}
</script>

</body>
</html>From:https://w3schools.com/jsref/event_clientx.asp

Related Tutorials