I have the following code to load jQuery in a document from a certain website
j=document.createElement("SCRIPT");
j.src="http://code.jquery.com/jquery-latest.pack.js";
document.getElementsByTagName("HEAD")[0].appendChild(j);
var J = jQuery.noConflict();
If I run this as a block from the console, I get
ReferenceError: jQuery is not defined
However, if I enter each line manually, the last line runs fine and I don’t get the exception.
Is there something I’m missing — maybe the DOM needs a few more milliseconds to finish processing the previous command?
Whatever the problem is, does any one know how to resolve this situation?
This occurs in chrome and firefox with dev tools and firebug respectively.
1 Answer