Does anybody know a way to detect if the jQuery library was loaded and if not append it and start a script as a fallback solution after it's loaded to the DOM?
Here's my script:
if (typeof jQuery == 'undefined') {
// if jQuery Library is not loaded
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
document.body.appendChild(script);
startScript();
} else {
// cool, jQuery Library is loaded
startScript();
}
function startScript() {
$.noConflict();
jQuery(document).ready(function($){
.... // my jquery code
});
}
Of course, above appends jQuery correctly but doesn't do anything because the script starts immidiately after appending. Any hint on this?
I appreciate any answer. Thanks!