How to setup jQuery on my web server?

To run jQuery on your web pages, add the library file within a pair of <script> tags. The location of the jQuery library file is added under the <script> tags, which point to the location of the jQuery library file on the Web server.

Method 1: Local jQuery File

First, download the jQuery library from the official website and upload it to your web server. Then include it in your HTML file as shown below ?

<script src="jquery/jquery-3.2.1.min.js"></script>

Important: The location of the jQuery file on the web server should be exactly the same as what you specified in the script tags. Make sure the file path is correct relative to your HTML file.

Method 2: Using CDN (Recommended)

If you don't want to go through the hassles of setting up jQuery locally, then use a CDN (Content Delivery Network). With Google CDN, it will be an easier way to include jQuery without any need to upload it on your web server.

Here's how to add jQuery using Google CDN ?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Complete HTML Example

Here's a complete HTML document showing how to include jQuery and use it ?

<!DOCTYPE html>
<html>
<head>
    <title>jQuery Setup Example</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
    <h1 id="heading">Hello World</h1>
    <script>
        $(document).ready(function(){
            $("#heading").click(function(){
                alert("jQuery is working!");
            });
        });
    </script>
</body>
</html>

Conclusion

Setting up jQuery on your web server can be done either by hosting the library file locally or by using a CDN link. The CDN method is generally preferred as it's faster and doesn't require file management on your server.

Updated on: 2026-03-13T17:43:18+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements