Chris
Chris

Reputation: 167

jQuery Offset wrong on refresh of page

I'm using jQuery offset function to place an absolutely positioned DIV over an anchor element.

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

When the page loads up this works fine, however, if I reload the page by hitting F5, it displays the DIV slightly offset from where it shoud be. If I then go page back-forward in the browser its in the right place again!!

This is an issue with latest Chrome and Firefox, but not with IE9.

Any ideas?

Chris.

Upvotes: 6

Views: 3238

Answers (1)

Raphael
Raphael

Reputation: 131

Try it in the $(window).load event instead of $(document).ready.

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

Upvotes: 13

Related Questions