I want to find out if a particular absolutely positioned element on my page is visible. I want to use offestParent() to cumulatively add up the offsets from the 'root' of the document, and use $ (window).scrollTop() to find out the amount of scrolling. My code (excluding the calculation of the scrolling) is:
var myelement = $("#elementtocheck"); var cumtop = 0; while (!($(myelement).is("body"))){ //this is the bit that I must be messing up cumtop += $(myelement).position().top; myelement = $(myelement).offsetParent(); }; If I use the test shown in the while loop, it works in Firefox, but in IE it adds the window scoll to the cumulative answer. If I use: while (!($(myelement).is("html"))) it gives the right answer in IE (6&7) i.e. the answer does not add in the scroll amount, but in Firefox this gives an endless loop. This must be done all the time. What is the right jQuery test to find the top of the positioning hierarchy that gives consistent answers?