开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜