jquery position() in plain javascript
I have the following line of code:
var newLeftPos = $('span#s' + i).position().left - parseInt($('span#s' + i).css('width'), 10);
It works great in ie6 and upwards but I also need to get it to work for ie5.5. (Let's not argue about that now - I know - but I have no option)
I'm certain it falls on the .position() while I'm testing on ie5.5 with jquery 1.2
How could I do the same in plain javascript? Could "offsetParent" help me here? Apparently ie5.5 supports that.
Thanks i开发者_开发百科n advance.
You are looking for offsetParent, offsetLeft and offsetRight.
As you can see in the link, looks like they are supported even by old granny IE5.5.
Check this text page to see if they are really supported by your browser first.
Then your function should be something like
var span = document.getElementById('s' + i);
var newLeftPos = span.offsetWidth - parseInt(span.style.width);
精彩评论