views:

49

answers:

3

I'm adding resizable to several div tags that are part of a complex page. But the $(document).ready() if executing too early. Not everything has been parsed and the resizable fails.

How do I get jQuery to really wait until the document is ready?

I've tried...

$(document).ready()
$(document).load()
$(window).load()

By adding a temporary button with the same code as these, that I click after the page is rendered, I get the proper resizable UI.

I'm using jQuery v1.4.2 and jQuery UI v1.8.4 with Firefox v3.6.8.

+1  A: 

But the $(document).ready() if executing too early. Not everything has been parsed and the resizable fails.

This shouldn't be. ready() fires when the DOM has been parsed and rendered. The only thing that could still be loading is style sheets (don't know what to do about those) and images.

If your resizable depends on images being fully loaded, use the load event instead.

Pekka
No images, just HTML.
dacracot
Same problem with $(document).load().
dacracot
@dacracot then the problem must be somewhere else. These events are guaranteed to be rock-solid across all browsers. Can you describe in more detail what happens?
Pekka
@Pekka - Hard to describe when nothing happens. I added a button to the page temporarily with the same code as the ready function, and it works. So it does seem to be a timing issue. Using firebug and examining the HTML, I don't see the jQuery additions until after I click my temporary button.
dacracot
@dacracot maybe it's an order issue - something happening too early in the ready event? (The ready event is a queue, and most jQuery plugins append something to it.) Also, a live example might be helpful. I'm off for the day now, good luck!
Pekka
A: 

Try using $(window).load() rather than $(document).ready()... This will wait until EVERY single aspect has loaded to completion... a little slower but should iron out your bug

Aardvark
Same problem with $(window).load().
dacracot
A: 

Stupid should hurt.

I also had a body onload event that was executing after the jQuery events but on which the resizable was dependent.

Answer: Don't use both methods.

dacracot