Element offsetParent Property - Javascript DOM

Javascript examples for DOM:Element offsetParent

Description

The offsetParent property returns the nearest ancestor that has a position other than static.

Return Value

A Node object, representing nearest positioned ancestor

The following code shows how to get the offsetParent for a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<div id="test">
  <p>This is a test. This is a test. This is a test.</p>
  <p><button onclick="myFunction()">Test</button></p>
  <p>offsetParent is: <span id="demo"></span></p>
</div>// w  w  w  .ja v  a  2 s.c  om

<script>
function myFunction() {
    var testDiv = document.getElementById("test");
    document.getElementById("demo").innerHTML = testDiv.offsetParent;
}
</script>

</body>
</html>

Related Tutorials