Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Find Element's Position Relative to the Document</title> <style> #box{ width:150px; height:100px; background: orange; margin: 150px 100px; } </style> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function() { $("button").click(function(){ var offset = $("#box").offset(); alert("Current position of the box is: (left: " + offset.left + ", top: " + offset.top + ")"); }); }); </script> </head> <body> <button type="button">Get Box Position</button> <p><strong>Note:</strong> Play with the value of margin property to see how the jQuery offest() method works.</p> <div id="box"></div> </body> </html>