Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat would make offsetParent null?
    primarykey
    data
    text
    <p>I am trying to do positioning in JavaScript. I am using a cumulative position function based on the <a href="http://www.quirksmode.org/js/findpos.html" rel="noreferrer" title="Find position">classic quirksmode function</a> that sums <code>offsetTop</code> and <code>offsetLeft</code> for each <code>offsetParent</code> until the top node.</p> <p>However, I am running into an issue where the element I'm interested in has no <code>offsetParent</code> in Firefox. In IE <code>offsetParent</code> exists, but <code>offsetTop</code> and <code>offsetLeft</code> all sum up to 0, so it has the same problem in effect as in Firefox.</p> <p>What would cause an element that is clearly visible and usable on the screen to not have an <code>offsetParent</code>? Or, more practically, how can I find the position of this element in order to place a drop-down beneath it?</p> <p><strong>Edit</strong>: Here's how to reproduce one particular instance of this (not solved by the currently-accepted answer):</p> <ol> <li>Open the <a href="http://stackoverflow.com">home page of Stack Overflow</a>.</li> <li><p>Run the following code in the Console of the web browser (e.g. Chromev21):</p> <pre class="lang-js prettyprint-override"><code>var e = document.querySelector('div'); console.log(e); // &lt;div id="notify-container"&gt;&lt;/div&gt; do{ var s = getComputedStyle(e); console.log(e.tagName,s.display,s.visibility,s.position,e.offsetParent); } while(e=e.parentElement) // DIV block visible fixed null // BODY block visible static null // HTML block visible static null </code></pre></li> </ol> <p><strong>Why is the <code>offsetParent</code> of that element <code>null</code>?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload