I have a canvas for drawing like that
<div id="canvas" style="position:relative;width:600px;height:300px;" onclick="q()"></div>
I need to handle the event when clicking on it and get the coordinates on the canvas where it was clicked
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to get the page x and y coordinates, and then minus the
canvasoffset to get them relative to thecanvas.jsFiddle.
You should consider attaching events unobtrusively, i.e. not using the
onclickHTML attribute.