19 Feb jQuery mousemove() method
Definition
The mousemove event triggers when the mouse pointer moves contained by the matched element. It gets fired by the jQuery mousemove() method.
Syntax
The following is the syntax,
1 2 3 |
$(selector).mousemove(func) |
The following is the parameter,
- func: When mousemove event is triggered, this function runs. This is optional parameter.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(document).mousemove(function(event){ $("p").text("X Coordinates: "+event.pageX + ", Y Coordinates: " + event.pageY); }); }); </script> </head> <body> <h2>Capturing mouse coordinates</h2> <p></p> </body> </html> |
The following is the output, displaying the mouse coordinates,
No Comments