Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <style> div { width: 200px; height: 100px; border: 1px solid black; } </style> <body> <h1>HTML DOM Events</h1> <h2>The onmousemove Event</h2> <p>Use the HTML DOM to assign an "onmousemove" event to a div element.</p> <div id="myDIV"></div> <p>Mouse over the rectangle above, and get the coordinates of your mouse pointer.</p> <p id="demo"></p> <script> document.getElementById("myDIV").onmousemove = function(event) {myFunction(event)}; function myFunction(e) { let x = e.clientX; let y = e.clientY; let coor = "Coordinates: (" + x + "," + y + ")"; document.getElementById("demo").innerHTML = coor; } </script> </body> </html>