Since jQuery is a JavaScript library, you will need to use a script tag to load it in.
Loading It Local
If you host your own server, you can download a copy from jQuery’s website, and then add it to a script tag to find on your server.
<script src="\js\jquery.js"><script>
Note: You must have a server. Most browsers will not allow you to load an external JavaScript file from a local file.
Note: This assumes that you have downloaded the file to a folder called js, under your main website folder. You may need to update the path and/or filename depending upon how you have configured your site and what you called the file.
Loading from a CDN
You can choose to load jQuery from a CDN, or Content Delivery Network. These spread the work of hosting files across the globe, so your users download from a server physically closer to them. Additionally, if they visit another site, which is using jQuery through the CDN, before yours, it will already be in their cache – which will help your site load faster.
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"></script>
So why not always load from a CDN? Well, you might be on an Intranet site, which blocks external resources. Some countries will block some known CDN sites. And you may not like giving up the control of what happens if you cannot access that site because the service goes down, or away.
Note: The integrity
and crossorigin
attributes are used for Subresource Integrity (SRI) checking. This allows browsers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice whenever libraries are loaded from a third-party source. Read more about this at srihash.org.
Once Loaded… Now What?
Once you have added your library reference to your HTML page, you can then start to write code using the jQuery library. Common things done with jQuery include:
- Setting up a page once the document model is loaded
- Handling events from actions on the page
- Making AJAX calls to the server
- Manipulating the Page (add/changing/removing elements)
- Working with different Effects
- and more… or combining some of these…
Getting Started with jQuery was originally found on Access 2 Learn