4

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.

James Black
  • 41,583
  • 10
  • 86
  • 166

2 Answers2

1

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

Myles
  • 20,860
  • 4
  • 28
  • 37
  • Weird. Why would they want the user to start poking around before the page is ready? – Nosredna Nov 09 '09 at 05:22
  • 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 Nov 09 '09 at 05:22
  • 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 Nov 09 '09 at 05:24
  • Maybe. I just played around in Google Docs and it looked like I had a busy cursor until everything was ready anyway. – Nosredna Nov 09 '09 at 05:28
1

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

Cross Browser JavaScript DOMContentLoaded

Nosredna
  • 83,000
  • 15
  • 95
  • 122
  • 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 Nov 09 '09 at 05:29