addEventListener("mousemove", function(event)); - Javascript DOM Event

Javascript examples for DOM Event:addEventListener

Description

The onmousemove event occurs when the pointer is moving while it is over an element.

Summary

Bubbles Yes
Cancelable Yes
Supported HTML tags: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div {// w w w.  j a va  2 s  .c  o m
    width: 200px;
    height: 100px;
    border: 1px solid black;
}
</style>
</head>
<body>

<div id="myDIV"></div>

<p id="demo"></p>

<script>
document.getElementById("myDIV").addEventListener("mousemove", function(event) {
    myFunction(event);
});

function myFunction(e) {
    var x = e.clientX;
    var y = e.clientY;
    var coor = "Coordinates: (" + x + "," + y + ")";
    document.getElementById("demo").innerHTML = coor;
}
</script>

</body>
</html>

Related Tutorials