Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Mouse events</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>#box{width:160px;height:90px;background:#e3f2fd;border:1px solid #90caf9;}</style> </head> <body> <div id="box">Hover / move / leave me</div> <pre id="out"></pre> <script> $("#box").on("mouseenter", function(){ $("#out").text("mouseenter"); }); $("#box").on("mousemove", function(e){ $("#out").text("mousemove: " + e.offsetX + "," + e.offsetY); }); $("#box").on("mouseleave", function(){ $("#out").text("mouseleave"); }); </script> </body> </html>
Output