0

How would I get the coordinates of a mouse click on an HTML5 canvas using Javascript?

Sorry I don't have a code example or anything, but this is a pretty simple question.

rshea0
  • 11,769
  • 9
  • 27
  • 40
  • 1
    It's so simple there are [tons](http://stackoverflow.com/questions/55677/how-do-i-get-the-coordinates-of-a-mouse-click-on-a-canvas-element) of [duplicates](http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas). – pimvdb Feb 22 '12 at 21:06

1 Answers1

2
$("canvas").mousedown(function(e) {
    console.log('Clicked: ' + e.offsetX + ', ' + e.offsetY);
});

P.S. This solution assumes that you're using jQuery. This is definitely doable without jQuery.

dragon
  • 1,747
  • 15
  • 18