event.clientX/clientY

In this chapter you will learn:

  1. How to get the event location

Event location

The following code prints out the event location by using the pageX and pageY properties.

<html><!--  j a  v  a2  s. co  m-->
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("div").mouseover(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>
         <div>   
            <span>Move the mouse over the div.</span>
            <span>&nbsp;</span>
          </div>
          <div>java2s.com</div>
    </body>
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. Find out the click event coordinates
Home » jQuery » Event
Event
Event attributes
event.keycode
event.clientX/clientY
pageX/pageY
Cancel event
Event target
bind
.blur()
.change()
.click()
.error()
.dblclick()
.delegate()
.die()
.focus()
.hover()
.keydown()
.keypress()
.keyup()
.live()
.load()
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseover()
.mouseout()
.mouseup()
.off()
.on()
.one()
.ready()
.resize()
.scroll()
.select()
.submit()
.toggle()
.trigger()
.triggerHandler()
.unbind()
.undelegate()
.unload()