how can i find location of div code example

Example 1: Get the position of a div/span tag

function getPos(el) {
    // yay readability
    for (var lx=0, ly=0;
         el != null;
         lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return {x: lx,y: ly};
}

Example 2: div element position in screen

function offset(el) {    var rect = el.getBoundingClientRect(),    scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,    scrollTop = window.pageYOffset || document.documentElement.scrollTop;    return { top: rect.top + scrollTop, left: rect.left + scrollLeft }}
// example usevar div = document.querySelector('div');var divOffset = offset(div);console.log(divOffset.left, divOffset.top);