JQuery Position()

jQuery position() method is the used to get the current coordinates of the first element in the set of matched elements, relative to the offset parent.

position() method retrieves the current position of an element relative to the parent element while the offset() method retrieves the current position relative to the document.

Below the syntax of position().


<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>jQuery position()</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
$(document).ready(function() {
  $("#button").click(function() {
     var offset = $("p").position();
	 alert("Top: " + offset.top + " Left: " + offset.left);
 <p style="margin:10px 0 0 10px"><lorem ipsum dolor sit</p>
 <button style="margin:0 0 10px 0;background:#e8e8e8;" class="btn" id="button">Click here to return offset coordinate of p element</button><br />