+ 1
How to get coordinates of mouse-clicks?
I have a div element with id = display-image, In the element images are displayed. I want to know the coordinates when the mouse clicks on the image only. Since the image fits in the div element, then the coordinate of the any click within display-image div needs to be recorded.
2 Answers
+ 3
The click event will provide an event object, the coordinates of the mouse click are properties of click event object. You can get the coordinates relative to the window, document or target element.
The code provided is showing the coordinates relative to the target element, event.offsetX and event.offsetY
https://code.sololearn.com/Wf0gjzpbZZCk
The MouseEvent Object
https://www.w3schools.com/jsref/obj_mouseevent.asp
+ 3
Maybe you can use one of these:
https://stackoverflow.com/questions/14651306/get-mouse-position-within-div