Careless Careless - 1 year ago 83
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();


Answer Source

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));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download