How to use jQuery .position() to get the current coordinates of the first HTML element in the set of matched elements

1 Answer

0 votes
<!doctype html>
<html>
<head>
  <script src="js/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>

<p>jQuery</p>
<p>this is p last</p>
<script>
var p = $( "p:first" );
var position = p.position();
$( "p:last" ).text( "left: " + position.left + ", top: " + position.top );

/*
run:

jQuery

left: 10, top: 15

*/

</script>
</body>
</html>

 



answered Aug 22, 2016 by avibootz
...