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
- jQuery | position() with Examples
- Difference between on() and live() or bind() in jQuery
- How ajax works? Difference between angular js and jquery
- CSS | outline-offset Property
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery | jQuery.fx.off Property
- p5.js | position() Function
- How to position a div at the bottom of its container using CSS?
- CSS | background-position Property
- Insert string at specified position in PHP
- How to position a div at specific coordinates ?
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.