How to link jQuery from my local machine?

You can add jQuery using CDN or through downloading it on your local machine. For local installation, download the jQuery library on your local machine and include it in your HTML code. The following are the steps ?

  • Go to the jQuery website to download the latest version available.
  • Save the downloaded jquery-3.2.1.min.js file (or the latest version) in a directory of your website, e.g. /jquery.
  • Include the jQuery file in your HTML using the <script> tag with the correct path to your local file.

Linking jQuery Locally

Once you have downloaded and placed the jQuery file in your project directory, you need to reference it in your HTML document using a script tag. The src attribute should point to the local path where you saved the jQuery file.

Example

Here's a complete example showing how to link jQuery from your local machine ?

<html>
   <head>
      <title>jQuery Example</title>
      <script src = "/jquery/jquery-3.2.1.min.js"></script>
      <script>
         $(document).ready(function(){
            $("h1").css("color", "blue");
            $("h1").append(" - jQuery is working!");
         });
      </script>        
   </head>
   
   <body>
      <h1>Hello World</h1>
   </body>
</html>

The output of the above code is ?

Hello World - jQuery is working!
(The text will appear in blue color)

In this example, the $(document).ready() function ensures that the jQuery code runs after the HTML document is fully loaded. The script changes the color of the <h1> element to blue and appends additional text to demonstrate that jQuery is working properly.

Conclusion

Linking jQuery from your local machine involves downloading the jQuery library file and referencing it in your HTML using a script tag with the correct local path. This approach gives you full control over the jQuery version and ensures your website works even without internet connectivity.

Updated on: 2026-03-13T17:27:53+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements