Get X, Y Coordinates of Mouse Within Box


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $(function() {
  2. $("#demo-box").click(function(e) {
  3.  
  4. var offset = $(this).offset();
  5. var relativeX = (e.pageX - offset.left);
  6. var relativeY = (e.pageY - offset.top);
  7.  
  8. alert("X: " + relativeX + " Y: " + relativeY);
  9.  
  10. });
  11. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.