Skip to content

Instantly share code, notes, and snippets.

@daxxog
Created January 10, 2020 17:07
Show Gist options
  • Save daxxog/4a20152759e29e98a2b757db2e5bc5ab to your computer and use it in GitHub Desktop.
Save daxxog/4a20152759e29e98a2b757db2e5bc5ab to your computer and use it in GitHub Desktop.
Load jQuery library using plain JavaScript (With callback)
//- https://www.sitepoint.com/dynamically-load-jquery-library-javascript/
//- Load jQuery library using plain JavaScript (With callback)
//- ---------------------------------------------------------------------
(function () {
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState) { //IE
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function () {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
loadScript("https://code.jquery.com/jquery-3.4.1.min.js", function () {
//jQuery loaded
console.log('jquery loaded');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment