<div class="container">
<div class="box"></div>
</div>
<div class="text-center" id="show"></div>
.container{
display: flex;
justify-content: center;
}
.box{
width: 200px;
height: 200px;
background: red;
position:relative;
}
.text-center{
text-align: center;
padding: 10px 0;
}
$(".box").click(function(e){
let xPos = e.pageX - $(this).offset().left;
let yPos = e.pageY - $(this).offset().top;
$("#show").text(`x: ${xPos}, y: ${yPos}`);
})
This Pen doesn't use any external CSS resources.