How to link jQuery in HTML page ?
Last Updated :
29 Jul, 2024
jQuery is one of the most popularly used JavaScript Libraries out there which is a lot easier to use than standard JavaScript as it provides many built-in functions to access. It is build using JavaScript capabilities, you are able to use all the functions that are available in JavaScript.
In this article, we will discuss how to link jQuery to the HTML page. There are two ways through which you can include the jQuery file in HTML code:
- By downloading the jQuery Library
- By including the jQuery from a CDN
Downloading the jQuery Library: In this method, we directly download the library through the website on our system. Basically, there are two versions to download:-
- Production Version - It is a compressed version used mainly for your live website.
- Development Version - It is an uncompressed version that is used for development and testing purposes.
We will use the development version for our purpose. Just follow through these steps to download the jQuery on your system -
- Open any browser and search for jquery.com (It is the official website for downloading jQuery Library).
- On the main page, you will find the download link on the right side. Click on the link shown.
- It will take you to the download page where you will be given some options to select. You have to download the uncompressed, development jQuery as shown below and make sure to keep it in the same folder where your HTML file is located. You have to right-click on the link and from the menu select "Save as...".

Now let's link it to our HTML code. Just add the following code under the <head> section of the HTML file:
<script src = "jquery-3.6.0.js" ></script>
Note: By default, the JavaScript file is saved by the above-given name (version here is 3.6.0). There may come newer versions to these, so refer to the file with that name.
Let's see an example to understand how it is done. Below is the HTML code for the same:
HTML
<!DOCTYPE html>
<html>
<head>
<!-- Linking of jQuery File
that we have downloaded -->
<script src="jquery-3.6.0.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("h2").html("Complete Portal for Geeks</b>");
});
});
</script>
</head>
<body>
<center>
<h2>GeeksforGeeks</h2>
<button>Click here</button>
</center>
</body>
</html>
Output:
2. Including the jQuery from a CDN: If you don't want to use the above method, here is the alternative solution for it. In this method, you have to include jQuery through a CDN (Content Delivery Network) like Google CDN. It's very simple, just add the following code under the <head> section of the HTML file:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Now let's see an example of it. Below is the HTML code:
HTML
<!DOCTYPE html>
<html>
<head>
<!--Linking of jQuery file using CDN-->
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
</script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("h2").html("Complete Portal for Geeks</b>");
});
});
</script>
</head>
<body>
<center>
<h2>GeeksforGeeks</h2>
<button>Click here</button>
</center>
</body>
</html>
Output:
Similar Reads
How To Link Pages In HTML? In HTML, linking pages is the fundamental practice that allows users to navigate from one web page to the another within same website or to an entirely different website. These links, also known as hyperlinks, are created using the <a> tag, which can direct the users to another HTML document,
5 min read
How To Link Two Pages In HTML ? The linking of two pages in HTML is a fundamental aspect of web development, used in over 95% of websites for navigation. The most common method is through the <a> (anchor) tag, which creates hyperlinks to other pages or resources. In this article, we will explore various ways to link pages in
3 min read
How to Create Links to Other Pages in HTML ? HTML links are like pathways on the internet. They connect one webpage to another. Imagine a link as having two parts: a starting point (where you click) and an endpoint (where you end up). When you click on a link, you're basically starting at one point (the anchor) and moving to another (the desti
2 min read
How to Link a Button to Another Page in HTML? Linking a button to another page is a common requirement in web development. It can allow the users to navigate between a website's different sections or pages. This can be done using the various HTML elements.PrerequisitesHTMLCSS1. Using <a> Tag Styled as ButtonThe <a> tag is traditiona
3 min read
How to use anchor tag to open links in HTML ? In this article, we will learn how to use anchor tags to open links in HTML and we will implement different operations using anchor tags in HTML. We will see in this article, how to redirect another website through an anchor tag and how to open a blank new tag for any new link to open an image in a
3 min read