Javascript examples for DOM:Element offsetParent
The offsetParent property returns the nearest ancestor that has a position other than static.
A Node object, representing nearest positioned ancestor
The following code shows how to get the offsetParent for a <div> element:
<!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>