I am adding jQuery in dynamically due to the requirements of my project. However, when the below function is called jQuery is not defined
is displayed in the console. However, if I write alert(jQuery)
in the console it returns function (a,b){return new m.fn.init(a,b)}
, so I know that it is loaded. Does anyone have any suggestions?
function AddExternals(){
if (!jQuery){
var jq = document.createElement("script");
jq.type = "text/javascript";
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js";
document.getElementsByTagName("head")[0].appendChild(jq);
console.log("Added jQuery!");
} else {
console.log("jQuery already exists.")
}
}