I am having a cross browser issue with the offset()
function in jQuery. For example, I am looking for the offset of an anchor tag
eg. $('#anchorid').offset().top
As you can see the difference in each returned value. I am not too concerned with the difference between FF & IE8 but I am with IE7 and the others.
Is there another function I could use that would be the same or similar cross browsers or a possible fix for this?
The chances are there is something wrong (non-crossbrowser) with your markup. But as alternative you could try using native javascript instead.
document.getElementById('anchorid').offsetTop
Of if you wanted to get the offset on the whole page you could use a function like:
function findTotalOffset(obj) {
var ol = ot = 0;
if (obj.offsetParent) {
do {
ol += obj.offsetLeft;
ot += obj.offsetTop;
}while (obj = obj.offsetParent);
}
return {left : ol, top : ot};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With