Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery offsetParent() method

jQuery offsetParent() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Settings

The background color of the element's nearest positioned ancestor:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

offsetParent

(

)

.

css

(

"

background-color

"

,

"

red

"

)

;

}

)

;

Try it »


Definition and Usage

The offsetParent() method returns the first positioned ancestor element.

**Tip:** An element is positioned via the position property (relative, absolute, or fixed) in jQuery or CSS.


Syntax

$(

selector

).offsetParent()


jQuery HTML/CSS methods jQuery HTML/CSS methods