views:

16

answers:

1

i wonder if i use

google.load("jquery", 1);
google.setOnLoadCallback(function() {
    // i still need to check if document has finished loading with 
    $(function() {
        // do stuff
    });
});

the question is when google.setOnLoadCallback() is called it does not mean the document has finished loading right? or can i do stuff like ... below ... straight away?

google.setOnLoadCallback(function() {
    $("#elem").doSomething();
});
+1  A: 

From Google AJAX API docs:

google.setOnLoadCallback is used as a helper for window.onload, which only happens once, when the document is loading. Therefore, for dynamic loading of the API (such as after user interaction), google.load with the callback option should be used instead (see below).

window.load will always fire after DOMContentLoaded that is the equivalent of jQuery(document).ready for most cases. When not available, jQuery will fallback to onreadystatechange or onload (IE), or load (standard).

Since worst case if both jQuery and google falling back to the load event, you can safely use the second method.

Anurag