Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 in advance.

like image 200
Tuomas Avatar asked Sep 12 '11 14:09

Tuomas


1 Answers

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);
like image 133
Jose Faeti Avatar answered Oct 05 '22 23:10

Jose Faeti