-3

Is it possible to know the click position in the javascript page? So, if you know the x,y position and want to the user to click that, return x,y? and making some maths, if the object in my page is a circle, can I add the polar ecuation coordinates of the circle in the (x,y)?

already tryed this when the image is clicked

 var container = document.getElementById("portada");
container.addEventListener("onClick", getClickPosition, false);

function getClickPosition(e){
var xpos = e.clientX;
var ypos = e.clientY;
console.log("x"+xpos);
console.log("y"+ypos);
}

But it gives me the undefined x and y, just tryed a similiar one and still undefined, any suggest?

Carlos Montiel
  • 301
  • 1
  • 4
  • 16
  • 1
    You should show some code you tried, or examples you are trying to follow. The question is being downvoted because it appears you didn't researched and tried yourself before asking. It mat not be the case though. – Italo Ayres Feb 24 '16 at 20:13
  • @ItaloAyres added js function – Carlos Montiel Feb 24 '16 at 20:35
  • `onClick` should be `click` as in `container.addEventListener("click", getClickPosition, false);` – traktor Feb 24 '16 at 22:07

1 Answers1

1

This could help. https://jsfiddle.net/oqmvutfc/

$(document).on('click',function(e){
    alert('x:'+e.pageX+' y:'+e.pageY);
});

e.pageX returns the X position and e.pageY returns the Y position.

rorymorris89
  • 1,144
  • 7
  • 14