jQuery offsetParent() Method

The jQuery offsetParent() method can be used to get the first positioned parent element. If you place the selected element inside another element, it returns the first positioned parent element.

jQuery offsetParent() Method

Syntax

The syntax of this method is given below:-

Get the first positioned parent element
$(selector).offsetParent()

The syntax contains no parameter to specify and use the method.

jQuery offsetParent() Method to Get First Positioned Parent Element

If you want to get the first positioned parent element, you have to use the jQuery offsetParent() method. You can apply the CSS to the parent after selecting the element. See the example below to apply the CSS property.

Example

Test it Live

Output

This is my paragraph.

When you click the button given above, the method applies the CSS background color to the first positioned parent. It adds a background color to the element when you click the button given above.

You may also like to read

I hope you like this tutorial on jQuery offsetParent() method. If you have any queries regarding the tutorial, please comment below.

References