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 fine in ie6 and above, but I also need to get it to work for ie.5.5. (Let's not argue about this now - I know - but I have no choice)

I am sure it falls on .position () while I test ie.5.5 with jquery 1.2

How can I do the same in plain javascript? Can "offsetParent" help me here? IE5.5 seems to support this.

Thanks in advance.

+4
source share
1 answer

You are looking for offsetParent , offsetLeft and offsetRight.

As you can see in the link, it looks like they are supported even by the old IE5.5 grandmother.

Check this text page to make sure that they are indeed supported by your browser.

Then your function should be something like

 var span = document.getElementById('s' + i); var newLeftPos = span.offsetWidth - parseInt(span.style.width); 
+2
source

All Articles