8
I would like to know how to load the jQuery library with pure Javascript and run something simple with jQuery after its load?
My code is like this:
function colocaScript(){
var scriptJquery = document.createElement('script')
scriptJquery.type = 'text/javascript';
scriptJquery.src = "http://code.jquery.com/jquery-1.10.2.min.js";
scriptJquery.async = true;
headHTML = document.getElementsByTagName('head')[0];
headHTML.insertBefore(scriptJquery,headHTML.firstChild);
}
colocaScript()
$(document).ready(function () {
alert("Ola Mundo");
})
It returns this error:
Uncaught ReferenceError: $ is not defined
I tested your code and it’s working perfectly, try it on a new page, clean, no content, just html skeleton.
– Paulo Roberto Rosa