DEV Community

johnss
johnss

Posted on

dynamically load javascript

just change ele.src to anything you want

(function () {
    var ele = document.createElement('script');
    ele.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js";
    ele.id = "JQuery";
    ele.onload = function () {
        //code to be executed when the document has been loaded
    };
    document.getElementsByTagName('head')[0].appendChild(ele);
})();

source https://stackoverflow.com/questions/10994335/javascript-head-body-or-jquery

Top comments (0)