Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  149] [ 5]  / answers: 1 / hits: 56277  / 16 Years ago, tue, february 17, 2009, 12:00:00

I'm using Google Ajax API and they suggest I use google.setOnLoadCallback() to do various things related to their API but I'm using also jQuery's $(document).ready() to do other JS things, not related to Google API.



Is it safe to mix these two approaches in one document? I did not notice any problems yet but I suppose it's a matter of scale.


More From » jquery

 Answers
20

You pretty much have to do this:



google.setOnLoadCallback(function() {
$(function() {
// init my stuff
});
});


You can't do $(document).ready() without $ (the jQuery object) being available, so that needs to go inside the callback. And you can't be sure the document is ready inside the callback, so you have to do ready() too.


[#99967] Monday, February 9, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cierra

Total Points: 504
Total Questions: 108
Total Answers: 109

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
;