I’m using code from a blog, which is very similar to the code in the answer to this SO question.
My problem is that the code places the jQuery include just fine, but for some reason, scripts after it are not recognizing that jQuery is loaded. What am I doing wrong?
I’ve placed the code in a jsFiddle.
if (!window.loadjQueryOnce)
{
function loadjQueryOnce(jQueryVersion)
{
jQueryVersion = typeof(jQueryVersion) != 'undefined' ? jQueryVersion : "1.7.2";
if (typeof jQuery === "undefined") {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
"http://ajax.googleapis.com/ajax/libs/jquery/" + jQueryVersion + "/jquery.min.js")
document.getElementsByTagName("head")[0].appendChild(script_tag);
}
}
}
The problem is that you’re not waiting for the script to be executed before the call in the HTML. See this example, which uses the code from the blog you mentioned. You need to put the code that relies on jQuery in the
mainfunction.