I am developing a bookmarklet that requires a specific version of jQuery be loaded on the page. When I have to dynamically insert a jQuery script tag to meet the requirments of the bookmarklet I want to wait for the onload or onreadystatechange event on the script tag before executing any function that requires jQuery.
For some reason the onload and/or onreadystatechange events do not fire. Any ideas on what I am doing wrong here?
var tag = document.createElement("script");
tag.type = "text/javascript";
tag.src = "http://ajax.microsoft.com/ajax/jquery/jquery-" + version + ".min.js";
tag.onload = tag.onreadystatechange = function () {
__log("info", "test");
__log("info", this.readyState);
};
document.getElementsByTagName('head')[0].appendChild(tag);
The FULL code: http://gist.github.com/405215