jQuery Tip: How to get mouse cursor position

In this jQuery tip post, We will see how can we get the mouse cursor position using jQuery.

Earlier I had posted about Provide highlighting effect on mouseover and mouseout, Find which mouse button clicked using jQuery and How to use hover method in jQuery. And in this post, find jQuery way to get the mouse cursor position.

Below jQuery code block will provide X and Y position of mouse cursor.
     $('#spnCursor').html("X Axis : " + e.pageX + " Y Axis : " + e.pageY);
When the DOM is ready, we listen for mousemove event. Whenever user moves the mouse then this event gets called and we bind the pageX and pageY property to the span element.
See live Demo and Code.
Don't forget to read:
Feel free to contact me for any help related to jQuery. I will gladly help you.

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..