add this code to your function

var done = false;
script.onload = script.onreadystatechange = function() {
                var rs = this.readyState;
                if (!done && (!rs || rs == "loaded" || rs == "complete")) {
                    done = true;
                    if (callback) {
                        callback();
                    }
                    script.onload = script.onreadystatechange = null;
                    if (head && script.parentNode) {
                        head.removeChild(script);
                    }

                }
            };

01.08.2011, 08:46, "dtang85" <[email protected]>:
> 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]

Reply via email to