Careless Careless - 5 months ago 9
Javascript Question

Show position where is clicked

Can someone tell me how to show position on mouse click. I am not asking for on click show div position... I am asking for this if I have :

<div id="div123" style="width: 300px; height: 300px;"></div>

And jquery :


var x = $("WHERE MOUSE CLICKED INSIDE #div123").position();



I have not tried, but this should work

$('#div123').click(function(e) {
    var posX = $(this).position().left
    var posY = $(this).position().top;
    alert( (e.pageX - posX) + ' , ' + (e.pageY - posY));