#1086 new
Viktor Kojouharov

Element#getOffsetParent returns a statically positioned element

Reported by Viktor Kojouharov | June 28th, 2010 @ 01:25 PM | in After 1.7

At least in Firefox 3.6, Element#getOffsetParent could return an element, which is statically positioned.

Specifically, getting the offset parent of a table cell descendant element returns the table cell 'td', since that is what the offsetParent of the descendant is set to. However, the 'td' is statically positioned, and should not be returned. This occurs if that element is statically positioned. If the element is relatively positioned for instance, it will return the correct ancestor. For this reason, Element#getOffsetParent() should skip offsetParent if it is statically positioned, and return the first ancestor with a real position.

Due to this, Element#positionedOffset returns incorrect offsets, which are based on a statically positioned table cells.

Comments and changes to this ticket

  • Andrew Dupont

    Andrew Dupont August 15th, 2010 @ 02:46 AM

    • Assigned user set to “Andrew Dupont”
    • Importance changed from “” to “Low”


    Can you write a small test page that demonstrates this issue?

  • Andrew Dupont

    Andrew Dupont August 15th, 2010 @ 02:46 AM

    • Tag changed from 1.7 layout dimensions, e to layout
  • Viktor Kojouharov

    Viktor Kojouharov August 15th, 2010 @ 04:46 PM

    This test case will illustrate the problem (break in chromium)

  • Andrew Dupont

    Andrew Dupont August 19th, 2010 @ 08:20 AM

    • Milestone set to 2.0
    • Importance changed from “Low” to “Medium”

    Let's take the two failing test cases individually.


    this.assertEqual(realParent, staticElement.getOffsetParent(), "static element");

    I don't think this is a valid test case. For statically-positioned elements, the containing block is defined as "the content edge of the nearest block-level, table cell or inline-block ancestor box." Which means that, in your example, browsers aren't mistaken when they report the td as the offsetParent for the static element.


    this.assertEqual(document.body, fixedElement.getOffsetParent(), "fixed element");

    This is just as problematic. The containing block for a fixed-position element isn't an element at all; it's the viewport. Which is why browsers report null as the offsetParent for that element. Returning document.body would be no more correct than what we currently do.

    We should've designed and documented these methods more carefully. We use a far-too-simplistic definition of what an "offset parent" is in our documentation for Element#getOffsetParent and Element#positionedOffset. And we try to give measurements in all scenarios — even when, as in the static example, it's not clear what the results mean, or even why they'd be useful.

    This is something we need to fix, but it's not a simple thing, so I'm gonna schedule this for the 2.0 milestone — which, for now, just means "not 1.7," since we're already at release candidate and it's too late to make decisions this big.

    Thanks for the work you put into this!

  • Viktor Kojouharov

    Viktor Kojouharov August 19th, 2010 @ 11:15 AM

    I agree that the documentation is a bit vague on this. And actually, only the static element test fails for me. The fixed element test does in fact return the document.body for my case. And if the specification states that a table cell should be returned, then it does behave accurately. The docs just need to mention that, and/or link to the TR.

  • Andrew Dupont

    Andrew Dupont August 22nd, 2010 @ 04:57 AM

    • Milestone changed from 2.0 to After 1.7
  • Mad Alex

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket