I am trying to include jQuery to an HTML page conditionally. It only needs to be added if it doesn\'t exist yet.
I am using the following code near the top of my bod
A script loads asynchronously. This means its contents are not directly available after appending the element.
Use onload
instead:
script = document.createElement('script');
script.onload = function() {
// jQuery is available now
};
script.type = 'text/javascript';
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js';
head.appendChild(script);