Posted By

ahmadassaf on 11/23/12


Tagged

jQueryjavascriptLoadDynamic


Versions (?)

Load jQuery dynamically from Javascript


 / Published in: JavaScript
 

Load jQuery dynamically in a page from Javascript

  1. // Anonymous "self-invoking" function
  2. (function() {
  3. // Load the script
  4. var script = document.createElement("SCRIPT");
  5. script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
  6. script.type = 'text/javascript';
  7. document.getElementsByTagName("head")[0].appendChild(script);
  8.  
  9. // Poll for jQuery to come into existance
  10. var checkReady = function(callback) {
  11. if (window.jQuery) {
  12. callback(jQuery);
  13. }
  14. else {
  15. window.setTimeout(function() { checkReady(callback); }, 100);
  16. }
  17. };
  18.  
  19. // Start polling...
  20. checkReady(function($) {
  21. // Use $ here...
  22. });
  23. })();

Report this snippet  

You need to login to post a comment.