Load jQuery with Javascript and use jQuery Load jQuery with Javascript and use jQuery jquery jquery

Load jQuery with Javascript and use jQuery


There's a working JSFiddle with a small example here, that demonstrates exactly what you are looking for (unless I've misunderstood your request): http://jsfiddle.net/9N7Z2/188/

There are a few issues with that method of loading javascript dynamically. When it comes to the very basal frameworks, like jQuery, you actually probably want to load them statically, because otherwise, you would have to write a whole JavaScript loading framework...

You could use some of the existing JavaScript loaders, or write your own by watching for window.jQuery to get defined.

// Immediately-invoked function expression(function() {  // Load the script  const script = document.createElement("script");  script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js';  script.type = 'text/javascript';  script.addEventListener('load', () => {    console.log(`jQuery ${$.fn.jquery} has been loaded successfully!`);    // use jQuery below  });  document.head.appendChild(script);})();