0

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 :

$("#div123").click(function(){

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

});
Careless
  • 45
  • 1
  • 7
  • 3
    try this http://stackoverflow.com/questions/4249648/jquery-get-mouse-position-within-an-element – einsh10 Apr 30 '16 at 23:32

2 Answers2

0

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));
});
0

You need to process the event object in the function.

$("#div123").click(function(e){
  e.pageX;
  e.pageY;
});

event.pageX

The mouse position relative to the left edge of the document.

event.pageY

The mouse position relative to the top edge of the document.

check the doc: https://api.jquery.com/category/events/event-object/

victor sosa
  • 899
  • 13
  • 27