Posted By

iTony on 03/15/10


Tagged

javascript


Versions (?)

element top, left position


 / Published in: JavaScript
 

  1. function getElementTopLeft(id) {
  2.  
  3. var ele = document.getElementById(id);
  4. var top = 0;
  5. var left = 0;
  6.  
  7. while(ele.tagName != "BODY") {
  8. top += ele.offsetTop;
  9. left += ele.offsetLeft;
  10. ele = ele.offsetParent;
  11. }
  12.  
  13. return { top: top, left: left };
  14.  
  15. }

Report this snippet  

You need to login to post a comment.