- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM offsetParent Property
The HTML DOM offsetParent property returns the referenced parent element from which child offsets are defined.
Following is the syntax −
Returning referenced offset parent element
HTMLelement.offsetParent
Let us see an example of HTML DOM offsetParent property −
Example
<!DOCTYPE html> <html> <head> <title>HTML DOM offsetParent</title> <style type="text/css"> #picForm { width:70%; margin: 0 auto; text-align: center; } input[type="button"] { border-radius: 10px; } #containerDiv { margin: 0 auto; } </style> </head> <body> <form id="picForm"> <fieldset> <legend>HTML-DOM-offsetParent</legend> <div id="containerDiv"> <img id="image" src="https://www.tutorialspoint.com/plsql/images/plsql-mini-logo.jpg"> </div> <input type="button" onclick="getParent()" value="Get offsetParent"> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var picForm = document.getElementById("picForm"); var containerDiv = document.getElementById("containerDiv"); function getParent() { divDisplay.textContent = 'Offset for Image form is referenced from: '+picForm.offsetParent; } </script> </body> </html>
Output
Before clicking any button −
After clicking ‘Get offsetParent’ button −
Advertisements