OneBite.Dev - Coding blog in a bite size

How to get x and y coordinate position when clicking on javascript

Learn How to get x and y coordinate position when firing on click event at javascript

Let’s see how to get x and y coordinate position when firing on click event at javascript

We need to catch event’s property, specifically, the pageX and pageY attribute.

<div onclick="handleClick(event)"> Test </div>

function handleClick(event){
 console.log('x :', event.pageX)
  console.log('y :', event.pageY)
}

Feel free to try!

javascript