Examine The Cursor Position on Screen in Jquery

<!DOCTYPE html>
<html>
<head>
  <title>Jquery height()</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>

<h2 id="position" align="center">Right Click To Know The Cursor Position</h2>

<script>

$(document).ready(function(){
    $(document).on("contextmenu",function(e){
    e.preventDefault();
    var name = $(this).attr("name");
    var top = e.pageY;
    var left = e.pageX
    $("#position").html("<font color='red' size='20'>Position from top: "+top+"px and left: "+left+"px</font");
});
});

</script>

</body>
</html>

Leave a Comment