Retrieve the position (X,Y) of an HTML element relative to the browser window


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.

This is easy as two lines in JS :

var elem = document.getElementById("id");    
alert(elem.getBoundingClientRect());