JavaScript/jQuery – offsetLeft and offsetTop


When hovering over a span I would like to get the offsetLeft and offsetTop values so I can make something hover near it. When I do this I get 0 for both values.

What is a better way to tackle this? I am using jQuery.

Assume I am starting with (looped by server-side scripting):

<span onmouseover="hoverNearMe(this.offsetLeft,this.offsetTop);">some username</span><br />

I'm giving the the answer rep out based on "code leverage"/DRY.
The longer function you could use over and over in your own js library.
The second short answer however is 100% correct too.

Best Answer

$(this).offset().left and $(this).offset().top