Hi all,

I did a bit of searching and noticed that a lot of people have trouble with offsetTop. I have a problem like that too, although the solutions given in the other threads don't seem to work for me.

So here's my problem:

On the page I've got a couple of divs (id = pos_x, where x is an increasing number). On the right side of the page I'm trying to get pictures (id = pic_pos_x) positioned to the corresponding div on the left.

In order to do that I fire this function for each image:

Code JavaScript:
function changeImagePos(elementid) {
 
    var obj_pic = document.getElementById('pic_pos_' + elementid);
    var obj_div = document.getElementById('pos_' + elementid);
 
    var pos = findPos(obj_div);
    var value = pos + 'px';
 
    obj_pic.style.top = value;
}
 
function findPos(obj) {
    var top = 0;
 
    if (obj.offsetParent) {
        top = obj.offsetTop
        while (obj = obj.offsetParent) {
            top += obj.offsetTop
        }
    }
    return top;
}
Note: the elementid in the first function is the number of the div (the x).

This works great in Firefox. But with Internet Explorer it always returns top = -1.

I tried some other functions I found on the web but none of them seem to work for me. Any chance any of you can help me out here?

Thanks in advance.

Regards,
Pepe