Home » jQuery position()

jQuery position()

by Online Tutorials Library

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.

Test it Now

Another example of jQuery position()

Test it Now

Next TopicjQuery addClass()

You may also like