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);
source share