'JS offset different results

I am working on a smaller webpage (onepage) and I stumbled upon something very strange. I am trying to get the exact offset top position of a alement. As you can se at the screenshot, the first result is logged via:

console.log($('section#members')[0].offsetTop);

And second result is just a log of:

console.log($('section#members'));

The second result is giving the correct result and the first is wrong. However when I try to get the second result(2), via the first code example it outputs the wrong result. Any idear why this is happening?

Regards, Simonenter image description here



Solution 1:[1]

I found out at last that the issue did happend because the way elements was loaded. In this case the js log was called before css stuff was rendered, so I guess that was the issue. Hope this helps somebody else :)

Solution 2:[2]

I know this is ancient, but I had the same problem and it's interesting how the result is off by 200px on both cases. But like you said it's a loading problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 simon
Solution 2 Stefanos Karakasis