Both the jQueryUI method the returns the object which contains integer co-ordinate properties of the top and left positions. The positions of top and left coordinates are returned in pixels. Both functions are applied only on visible elements, not on hidden elements.
Example: The example gives top and left co-ordinates of the box which contains the text.
- Before clicking any button:
- After clicking the button:
Difference between offset() and postion() Method:
|offset() Method||position() Method|
|The offset() method in jQuery returns the first found position of HTML element with respect to the document.||The position() method in jQuery returns the current position of HTML element with respect to its offset parent.|
|The jQuery UI offset() is relative to the document.||The jQuery UI position() is relative to the parent element.|
|When you want to position a new element on top of another one which is already existing, its better to use the jQuery offset() method.||When you want to position a new element near another DOM element within the same container, its better to use jQuery position() method.|
|The offset() method is mostly used in drag-and-drop functions.||The position() method is used to position an element relative to document, window or other elements like mouse or cursor.|
- jQuery | offset() with Examples
- CSS | outline-offset Property
- How to get rid of an element offset using CSS ?
- How to avoid undefined offset error in PHP ?
- How to set the offset property for ScrollSpy in Bootstrap ?
- jQuery UI | position() Method
- jQuery | position() with Examples
- How to get position of an element relative to the document or parent using jQuery ?
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- How ajax works? Difference between angular js and jquery
- Difference between on() and live() or bind() in jQuery
- Difference between Angular and jQuery
- Change the size and position of button in Kivy
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.