In order to get the location of an element relative to the document, jQuery offset() method is used. The offset() method is an inbuilt method in jQuery which is used to set or returns the offset coordinates of the selected element. We can also use the jQuery position() method. The position() method is an inbuilt method in jQuery which is used to find the position of the first matched element relative to its parent element in the DOM tree.
Below examples illustrate the above approach:
- How to get relative click coordinates on the target element using JQuery?
- How to remove parent element except its child element using jQuery ?
- JQuery | Get the n-th level parent of an element
- How to set position relative to top of a canvas circle using Fabric.js ?
- How to position relative to top of a text canvas using Fabric.js ?
- How to set position relative to left of a canvas circle using Fabric.js ?
- jQuery | :parent Selector
- jQuery | parent() & parents() with Examples
- jQuery | parent descendant Selector
- jQuery | parent > child Selector
- How to convert an HTML element or document into image ?
- jQuery UI | position() Method
- jQuery | position() with Examples
- What is the difference between position() and offset() in jQuery ?
- How to find the parent class name with known class in jQuery ?
- Retrieve the position (X,Y) of an element using HTML
- jQuery | Move an element into another element
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.