I want to know how to get the X and Y position of HTML elements such as img
and div
in JavaScript relative to the browser window.
You might be better served by using a JavaScript framework, that has functions to return such information (and so much more!) in a browser-independant fashion. Here are a few:
With these frameworks, you could do something like:
$('id-of-img').top
to get the y-pixel coordinate of the image.