9951 explained code solutions for 126 technologies

javascriptHow to get element position relative to window

var pos = document.querySelector('#id').getBoundingClientRect();
var x = pos.left;
var y = pos.top;ctrl + c

element selector to get position of


returns top/left/right/bottom coordinates of an element relative to the browser window

var x

will contain left coordinate

var y

will contain top coordinate