+2  A: 

Try the dimensions jQuery plugin. See this demo.

$('#myelement.').offset();
Pistos
A: 

You could subtract the div's offsetTop from the document.body.scrollTop

This seems to work on IE7 and FF3, but on a very simple page. I haven't checked with nested DIVs.

rslite
+5  A: 

You can do it in both - get the position relative to the document, then subtract the scroll position.

var e = document.getElementById('xxx');
var position = {x:0,y:0};
while (e)
{
    position.x += e.offsetLeft;
    position.y += e.offsetTop;
    e = e.offsetParent;
}

if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft))
{
    offset.x -= document.documentElement.scrollLeft;
    offset.y -= document.documentElement.scrollTop;
}
else if (document.body && (document.body.scrollTop || document.body.scrollLeft))
{
    offset.x -= document.body.scrollLeft;
    offset.y -= document.bodt.scrollTop;
}
else if (window.pageXOffset || window.pageYOffset)
{
    offset.x -= window.pageXOffset;
    offset.y -= window.pageYOffset;
}

alert(offset.x + '\n' + offset.y);
Greg
A: 

Using Prototype it would be:

$('divname').viewportOffset.top
$('divname').viewportOffset.left
Diodeus
A: 

In IE and Firefox 3, you can use getBoundingClientRect for this; no framework necessary.

But, yes, you should use a framework if you need to support other browsers as well.

savetheclocktower