jQuery Installation
- Previous page jQuery Introduction
- Next page jQuery Syntax
Add jQuery to your web page
To use jQuery, you need to download the jQuery library (which will be explained to you below) and include it in the web page you wish to use.
The jQuery library is a JavaScript file that you can reference in your HTML using the <script> tag:
<head> <script src="jquery.js"></script> </head>
Please note that the <script> tag should be located in the <head> section of the page.
Tip:Are you puzzled why we did not use type="text/javascript" in the <script> tag?
In HTML5, there is no need to do that. JavaScript is the default scripting language in HTML5 and all modern browsers!
Download jQuery
There are two versions of jQuery available for download:
- Production version - used in actual websites, simplified and compressed.
- Development version - used for testing and development (uncompressed, readable code)
Both versions can be downloaded from jQuery.com Download.
Tip:You can place the downloaded file in the same directory as the page, which is more convenient to use.
Alternative solution
If you do not want to download and store jQuery, you can also reference it through CDN (Content Delivery Network).
Both Google and Microsoft servers store jQuery.
To reference jQuery from Google or Microsoft, please use one of the following codes:
Google CDN:
<head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"> </script> </head>
Tip:To obtain the latest available version through Google CDN:
If you observe the Google URL - the jQuery version is specified in the URL (1.8.0). If you want to use the latest version of jQuery, you can also remove a number from the end of the version string (e.g., in this case, 1.8). Google will return the latest available version in the 1.8 series (1.8.0, 1.8.1, etc.), or you can also just leave the first number, then Google will return the latest available version in the 1 series (from 1.1.0 to 1.9.9).
Microsoft CDN:
<head> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"> </script> </head>
Tip:There is a significant advantage to using Google or Microsoft's jQuery:
Many users have already loaded jQuery from Google or Microsoft when visiting other sites. As a result, when they visit your site, jQuery is loaded from the cache, which can reduce loading time. At the same time, most CDNs can ensure that when users request files from them, responses are returned from the server closest to the user, which can also improve loading speed.
- Previous page jQuery Introduction
- Next page jQuery Syntax