Over a million developers have joined DZone.

Detecting Mouse Position

This is an easy way to determine the mouse position (click anywhere and the co-ordinates get displayed:


   Mouse co-ordinates

You can store them in form fields

x = y =

or as plain text

Of course knowing the co-ordinates also makes it possible to position elements based on the position of the mouse pointer. It will work for any mouse event Mouseover, mouseout, etc; just change click to the desired event in the final if statement of the script. More good stuff and articles at the home of real IT Mentors

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}