javascript - 如何在javascript中获取绝对元素的祖先定位元素?

标签 javascript html css

我是 HTML 新手。我看过了

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

那么如何找到位置最近的祖先元素呢?

最佳答案

元素对象有一个名为offsetParent 的属性。例如:

document.getElementById("ElementId").offsetParent  

关于javascript - 如何在javascript中获取绝对元素的祖先定位元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47887816/

相关文章:

javascript - 如何使用 JavaScript 禁用浏览器的后退按钮

html - 使用 nth-child 选择特定的 div 类

jquery - 如何使元素忽略特定样式表

javascript - WebStorm 中 CoffeeScript 中的 "Duplicate catch block #loc"?

html - 禁用网页的 Internet Explorer 11 阅读 View

javascript - 如何在 Chrome 中永久使用假 ui?

javascript - 使用 jQuery 动画使圆从中心变大

css - 是否可以在固定的 div 上叠加?

javascript - 在重叠元素上注册鼠标事件

javascript - 单击链接时提示用户确认