HTMLElement: offsetParent property
        
        
          
                Baseline
                
                  Widely available
                
                
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The HTMLElement.offsetParent read-only property returns a
reference to the element which is the closest (nearest in the containment hierarchy)
positioned ancestor element.
A positioned ancestor might be:
- a containing block for absolutely-positioned elements
- an element with a different effective zoom value (that is, the product of all zoom scales of its parents) from this element
- td,- th,- tablein case the element itself is static positioned.
If there is no positioned ancestor element, the body is returned.
Note:
offsetParent returns null in the following
situations:
- The element or any ancestor has the displayproperty set tonone.
- The element has the positionproperty set tofixed(Firefox returns<body>).
- The element is <body>or<html>.
offsetParent is useful because
offsetTop and
offsetLeft are relative to its padding edge.
Value
An object reference to the element in which the current element is offset.
Specifications
| Specification | 
|---|
| CSSOM View Module> # dom-htmlelement-offsetparent> | 
Browser compatibility
Loading…