1

I am having a problem with adding a basic onclick listener in canvas in javascript, I want to retrieve the (x, y) coordinates for it, I would appreciate any help please.

Thank you.

Blitz
  • 25
  • 1
  • 2
  • 7
  • 1
    check this http://stackoverflow.com/questions/9880279/how-do-i-add-a-simple-onclick-event-handler-to-a-canvas-element – topcat3 Feb 27 '13 at 12:39
  • I don't know what you already tried. But perhaps you try to add the event listener on the 2d context, not the canvas element. Anyway I recommand you to use http://raphaeljs.com/ – Ron van der Heijden Feb 27 '13 at 12:45

1 Answers1

3

Try this..

document.getElementById('canvasId').addEventListener('click',function(evt){
alert(evt.clientX + ',' + evt.clientY);
},false);
Prasath K
  • 4,950
  • 7
  • 23
  • 35