How to use offsetParent() Method in JQuery

In this article, I will explain use of offsetParent () Method in JQuery.
  • 2871

JQuery CSS offsetParent() Method

 offsetParent( ) method returns a jQuery collection with  a specified position element.




The following example shows how to offsetParent() method in jquery.

<!DOCTYPE html>



<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("button").click(function () {

            $("p").offsetParent().css("background-color", "blue");






<h2>offsetParent() Method Example</h2>

<div style="width:70%;position:absolute;left:20px;top:50px">

<div style="margin:50px;background-color:green">

<p>Click button to set the background color of the first positioned parent element of this paragraph.</p>

<button>Click on</button>







 Further Readings

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.