issue with getting position of an element
im having issue with getting position of an element. there are 4divs with position relative. but and float is left. when im trying to get the left position on an element it retur开发者_运维知识库ns null. in jquery it returns 0. can some one help me please.
Thanks, Dakshina.
This should work.
var el = document.getElementById(<id>);
var left=0, top=0;
do {
left += el.offsetLeft;
top += el.offsetTop;
}while(el = el.offsetParent);
// 'left' and 'top' will give you the x,y position.
精彩评论