179
jQuery position()
The jQuery position () method makes you able to retrieve the current position of an element relative to the parent element. It returns the position of the first matched element. This method returns the object with two properties: top and left position in pixels.
The jQuery position() method is different from jQuery offset() method because the position() method retrieves the current position of an element relative to the parent element while the offset() method retrieves the current position relative to the document.
The position() method is more useful when you want to position a new element near another one within the same containing DOM element.
Syntax:
Example of jQuery position() method
Let’s take an example to demonstrate the jQuery position() method.
Another example of jQuery position()
Next TopicjQuery addClass()