tags:

views:

44

answers:

1

I use this function to get the y-coordinate of an element relative to the page:

function getY(oElement)
{
  var curtop = 0;
  if (oElement.offsetParent) 
  {
    while (oElement.offsetParent) 
    {
      curtop += oElement.offsetTop;
      oElement = oElement.offsetParent;
    }
  }
  else if (oElement.y)
  {
    curtop += oElement.y;
  }

  return curtop;
}

Now I want to do the same thing but get the position relative to the bottom instead of the top, there doesn't seem to be something like 'offsetBottom'.

How can I do this?

Many thanks

+1  A: 

Compare it to the height of the body/document itself.

Jonathan Sampson
Thanks for your answer, I think I'll do this eventually if there's no other way. But isn't it possible to get the position relative to the bottom? Even just out of curiosity.
Waleed Eissa
Could work but I'm not sure as the browser does not know the size of a document until it is fully rendered. Also, I'm not sure if this value would change hiding / showing elements dynamically.
Edmundo
@Waleed - Getting that value is pretty trivial. It's just a matter of subtracting the offset from the document height.
Jonathan Sampson
@Edmundo You're absolutely right. The value would have to be figured late in the flow, after the rendering has completed.
Jonathan Sampson