Return to Snippet

Revision: 24902
at March 15, 2010 12:01 by iTony


Initial Code
function getElementTopLeft(id) {

    var ele = document.getElementById(id);
    var top = 0;
    var left = 0;
   
    while(ele.tagName != "BODY") {
        top += ele.offsetTop;
        left += ele.offsetLeft;
        ele = ele.offsetParent;
    }
   
    return { top: top, left: left };
   
}

Initial URL

                                

Initial Description

                                

Initial Title
element top, left position

Initial Tags
javascript

Initial Language
JavaScript