I'm encountering an issue with obtaining offsetX when mousedown occurs. Take a look at my code below
<!DOCTYPE html>
<html>
<body>
<div id="myP" onmousedown="mouseDown()">
Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph,
<p style="margin-left:50px">
and sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released,
</p>
and sets the color of the text to green.
</div>
<script>
function mouseDown() {
var left = event.offsetX;
var top = event.offsetY;
console.log(top+"::"+left);
}
</script>
</body>
</html>
When my mousedown is over the div area, I get the correct result that I desire. However, when my mouse is over the paragraph area, I receive incorrect results. I am confused because the event should be from the parent element which is the DIV element.
Received Result Case 1: when my mouse is over DIV Element top: 17px, left: 61px
Case 2: when my mouse is over DIV Element top: 11px, left: 9px