Get mouse event position with event.clientX and event.clientY - Javascript DOM

Javascript examples for DOM:Mouse Event

Description

Get mouse event position with event.clientX and event.clientY

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* w  w  w .j  a v a 2  s.c  o  m*/
document.onmouseover = function(event) {
   event = event || window.event;
   document.getElementById("mouseX").innerHTML=event.clientX;
   document.getElementById("mouseY").innerHTML=event.clientY;
}
    }

      </script> 
   </head> 
   <body> 
      <div id="mouseX"></div> 
      <div id="mouseY"></div>  
   </body>
</html>

Related Tutorials