jQuery offsetParent() method
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