Showing posts with label load-jquery-dynamically. Show all posts
Showing posts with label load-jquery-dynamically. Show all posts

Saturday, December 2, 2017

Load jQuery with Javascript and use jQuery | Load jQuery dynamically




(function() {
    function loadJQuery() {
      var startingTime = new Date().getTime();
      var script = document.createElement("SCRIPT");
      script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
      script.type = 'text/javascript';
      script.onload = function() {
        var $ = window.jQuery;
        $(function() {
              var endingTime = new Date().getTime();
              var tookTime = endingTime - startingTime;
              window.alert("jQuery is loaded, after " + tookTime + " milliseconds!, version=" + $.fn.jquery);
          });
      };
      document.getElementsByTagName("head")[0].appendChild(script);    
    }
    if (window.jQuery) {
     alert("JQuery loaded");
    }
    else {
     alert("JQuery not loaded");
      loadJQuery();
    }
})();


Check here for JSFiddle