I am trying to dynamically include jQuery into the <head>. Here's my code:
if (typeof jQuery == 'undefined') {
// jQuery is not loaded
var script = document.createElement('script');
script.src = 'resources/js/jquery.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
alert(typeof jQuery);
}
It works well and I see the <script> tag in <head>; the jquery.js file is also correct and error less. Even then all I get for alert(tyeof jQuery) is undefined. why?