I'm trying to get the mouse offset inside a square, but when I click on its children, the offset changes, now returning the mouse offset inside the children, and not the parent.
What I would like to achieve is to get the mouse offset inside the parent, even if I click inside the children. Thanks a lot!
Below is an example of the problem. (Look in the console)
$("#parent").click(function(e){
console.log(e.offsetX, e.offsetY)
});
.square{
position: relative;
height: 200px;
width: 200px;
background-color: red;
}
.small{
position: absolute;
top: 25px;
right: 25px;
height: 50px;
width: 50px;
background-color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="square" id="parent">
<div class="square small"></div>
</div>