Skip to content
Related Articles
Open in App
Not now

Related Articles

jQuery | offsetParent() with Example

Improve Article
Save Article
  • Last Updated : 30 Aug, 2021
Improve Article
Save Article

The offsetParent() method is an inbuilt method in jQuery which is used to find the first positioned parent element in the DOM tree.


Parameters: This method does not contains any parameter.
Return Value: This method returns the first positioned parent element.
Below example illustrates the offsetParent() method in jQuery:


<!DOCTYPE html>
       <title>The offsetParent Method</title>
      <script src=
      <!-- jQuery code to show the working of this method -->
                 $("p").offsetParent().css("background-color", "green");
         #d1 {
             border:1px solid black;
         #d2 {
             border:1px solid black;
         p {
             padding-left: 80px;
             font-weight: bold;
      <div id="d1">
         <div id="d2">
            <!-- click on this paragraph -->
<p>Welcome to GeeksforGeeks!</p>



Related Articles: 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!