Total Page Preview:   000000000901

What is offset() and position() in jQuery?

 jQuery offset() and position()

 jQuery, the offset() and position() methods are used to retrieve the current coordinates of an element relative to the document or its positioned ancestor, respectively.

1-offset() Method:
The offset() method gets the current coordinates of the first element in the set of matched elements, relative to the document.
The returned object has two properties: top and left, representing the top and left positions of the element.
2-position() Method:
The position() method gets the current coordinates of the first element in the set of matched elements, relative to its offset parent.
The returned object has two properties: top and left, representing the top and left positions of the element relative to its offset parent.
In the examples, jQuery is included using a CDN, and the script is included inside a $(document).ready() function to ensure the DOM is fully loaded before manipulating it. The examples demonstrate how to use offset() and position() to retrieve the coordinates of an element and log them to the console.


 

 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments

Navneet Mishra
25-Nov-2016
Nice Articles. Move forward for gr8 future.
Palmos
14-Jul-2021
I have read so many articles regarding the blogger lovers except this piece of writing is in fact a pleasant article, keep it up.