Kiran Bhirde
Kiran Bhirde

Reputation: 93

how to get ancestor positioned element of an absolute element in javascript?

I am new to HTML. I have read that

"An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed)."

So how to find that nearest positioned ancestor element?

Upvotes: 3

Views: 225

Answers (1)

Kiran Bhirde
Kiran Bhirde

Reputation: 93

There is a property called offsetParent for element object. ex:

document.getElementById("ElementId").offsetParent  

Upvotes: 5

Related Questions