Get element position

Description

The following code shows how to get element position.

Example


<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {<!--from  w  w w .  j ava 2  s.c  om-->
    $("*", document.body).click(function(e) {
      var position = $(this).position();
      e.stopPropagation();
      alert(position.left);
      alert(position.top);
    });
  });
</script>
</head>
<body>
  <b>Hello java2s.com java2s.co m</b>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities