You might want to look at a script loader (or the source!) like RequireJS: www.requirejs.org
On 1 Aug 2011, at 05:46, dtang85 <[email protected]> wrote: > When you are using the DOM based approach to load JS, is there an > event that's fired once the source has been completely downloaded and > ready to use? > > In my simple example, I am downloading jQuery on demand, and the page > throws a JS error because the jQuery object isnt immediately available > for use after I call getJS(). > > > function getJS(src) { > var script = document.createElement('script'); > script.type = 'text/javascript'; > script.src = src; > document.getElementsByTagName("head")[0].appendChild(script); > } > > document.getElementById('link').onclick = function () { > getJS('jquery.min.js'); > > //throws an error at this point in the invocation of the > function > $('#someP').html('this is a test that jquery has been loaded.'); > } > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
