How To Load Jquery In Javascript

jQuery is a widely used JavaScript library that simplifies HTML document traversing, event handling, animating, and Ajax interactions. In this blog post, we will learn how to load the jQuery library in JavaScript.

Loading jQuery Using a Script Tag

The most common method to load jQuery in your project is to use a script tag. You can either download jQuery from the official website and host it locally or use a Content Delivery Network (CDN) like Google or Microsoft.

To load jQuery from a CDN, simply add the following script tag to the head of your HTML file:

    <script src=""></script>

Make sure to insert this script tag before any other scripts that rely on jQuery. Once the library is loaded, you can start using jQuery in your JavaScript code.

Loading jQuery Dynamically in JavaScript

In some cases, you may need to load jQuery dynamically in your JavaScript code. You can achieve this by creating a new script element and setting its src attribute to the jQuery library’s URL. Then, you can listen for the onload event to know when the library has loaded successfully.

Here’s an example of how to do this:

    function loadJQuery(callback) {
        var script = document.createElement("script");
        script.src = "";
        script.type = "text/javascript";
        script.onload = function() {

    loadJQuery(function($) {
        // Now you can use jQuery with the variable $
        console.log("jQuery version:", $.fn.jquery);

In this example, the loadJQuery function creates a new script element, sets its src attribute to the jQuery library’s URL, and appends it to the head of the document. When the library is loaded, it calls the supplied callback function with the loaded jQuery object.


Now you know how to load jQuery in your JavaScript projects using both the traditional script tag and by dynamically creating a script element. Remember to always include the jQuery library before any other scripts that depend on it to ensure they can access jQuery’s functionality.