views:

149

answers:

2

I am looking for something like the $(document).ready function in jQuery, as I work on experimenting with using Closure.

So, my question is simple, is there a function I am missing that will allow me to wait until my function is called when the DOM tree is done?

I use unobtrusive javascript, so the idea of putting any javascript in my html is such a negative, if that is required.

+1  A: 

Looks like you're out of luck according to this. Inline script blocks appears to be your only choice.

Myles
Weird. Why would they want the user to start poking around before the page is ready?
Nosredna
Thank you. :( I guess I will use my standard javascript snippet for this functionality, but, this is annoying that they did it intentionally.
James Black
There is some sense to that actually, a lot of what is loaded on a page isn't used/necessary until later. Getting the page responsive with the most common elements loading first would make for a better UI, and Google does have some of the more responsive web apps.
Myles
Maybe. I just played around in Google Docs and it looked like I had a busy cursor until everything was ready anyway.
Nosredna
A: 

If you want to do it your way (instead of Google's way), perhaps this would work for you.

Cross Browser JavaScript DOMContentLoaded

Nosredna
Thank you. I have a snippet of code I have been using for about 3 years that works fine, and I just tried it in my first application, it printed "Hello World!". :)
James Black
Well, good luck. Sounds like you're off and running.
Nosredna