Understanding jQuery Mousemove Event – .mousemove()

Understanding jQuery Mousemove Event – .mousemove()

The jQuery Mousemove event provides real time X and Y coordinates of the mouse pointer. You can use it to find the current position of your mouse.

Syntax – jQuery .mousemove() event

$(selector).mousemove(function (e) {
// code
});
The jQuery Click event is the most used event in web development, and you should know what are the best ways to use it.

Example – Finding the X and Y coordinates of mouse with .mousemove() event

I have a div element, so when I move my mouse over it then I should get the X and Y coordinates of the pointer.

To create this code I will use the .mousemove() event as shown below:

<div id="div1">Move Mouse Here</div>
 
$("#div1").mousemove(function (e) {
    $(this).html("X coordinate: " + e.pageX + "<br>Y coordinate: " + e.pageY)
});

Download source codes:

DOWNLOAD

SHARE THIS ARTICLE

  • linkedin
  • reddit
yogihosting

ABOUT THE AUTHOR

I hope you enjoyed reading this tutorial. If it helped you then consider buying a cup of coffee for me. This will help me in writing more such good tutorials for the readers. Thank you. Buy Me A Coffee donate