I am working on javascript.


I have a frame in which I have many elements(actually they are images).
when I select an element using mouse and then try to navigate down/up using arrow keys(from keyboard), scrollbar should move accordingly.
The element which we have selected should be visible.

This is working fine in Mozilla(Firefox.).

This is not working in IE(I am using IE8).

I tried to find the element location(offset values of element) in the window and move scrollbar to respective position.

Below is the function in which I tried to find element location.

function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}

But I am not able to get offsetLeft/offsetTop/offsetParent values(in Mozilla and IE).


Can you please tell me if I have gone wrong some where?

if there is any other way to get element position, please guide me.