JQuery Offset error while refreshing page

I use the jQuery offset function to place an absolutely positioned DIV over the anchor element.

$("#marker1").offset({ top: $("#<%= hypHowItWorks.ClientID %>").offset().top, left: $("#<%= hypHowItWorks.ClientID %>").offset().left });
$("#marker1").width( $("#<%= hypHowItWorks.ClientID %>").outerWidth() );

When the page loads, this works great, however, if I reload the page by pressing F5, it displays a DIV slightly offset from where it will be. If I go back to the page in the browser to the right place again!

This is a problem with the latest Chrome and Firefox, but not with IE9.

Any ideas?

Chris.

+5
source share
1 answer

Try in $(window).loadinstead $(document).ready.

I had the same problem and I could fix it with a trick!

+13
source

All Articles