javascript - jQuery cannot be accessed properly after being loaded dynamically? -
i trying write small check test jquery, , if not present, dynamically load copy script can run it. sets no conflict in case else present uses $, , runs script - small menu.
however, upon testing jquery loaded script, fails execute: "jquery not defined."
i know jquery has come first before functions use it, there way fix when dynamically installed?
(function() { console.log("loaded"); if(!window.jquery) { var script = document.createelement('script'); script.type = "text/javascript"; script.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"; document.getelementsbytagname('head')[0].appendchild(script); jquery.noconflict(); } })();
you're not waiting until script has loaded.
script.onload = function(){ // whatever };
Comments
Post a Comment