I'd like to pull in the jquery library from my javscript include.
Does this work 100% of the time? Is there a better way?
(function() {
var loadJquery = function (cb) {
var addLibs = function () {
if (typeof(document.body) == "undefined" || document.body === null) {
setTimeout(addLibs, 100);
return;
}
var node = document.createElement("script");
node.src = "http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js";
document.body.appendChild(node);
checkLib();
};
var checkLib = function () {
if (typeof($) == "undefined" || $("*") === null) {
setTimeout(checkLib, 100);
return;
}
cb($.noConflict());
}
addLibs();
}
loadJquery(function($){
// Do stuff with $
$(document.body).css("background", "black");
});
})();
Change the node.src
and $.noConflict
to YUI
if you want YUI3, or YAHOO
if you're YUI2, etc.