Mega Code Archive

 
Categories / JavaScript Tutorial / JQuery
 

Show the mouse coordinates when the mouse is moved over the yellow div Coordinates are relative to the window which in this case is

< html>   <head>     <script type="text/javascript" src="js/jquery-1.3.2.js"></script>     <script type="text/javascript">         $(document).ready(function(){             $("div").mousemove(function(e){               var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";               var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";               $("span:first").text("( e.pageX, e.pageY ) - " + pageCoords);               $("span:last").text("( e.clientX, e.clientY ) - " + clientCoords);             });         });     </script>   </head>   <body>     <body>          <p>                <span>Move the mouse over the div.</span>             <span>&nbsp;</span>           </p>           <div>asdf</div>     </body> </html>