jQuery: How to use jQuery in a project and confirm it is working

The fastest way to make jQuery available for a project is to use a CDN in the HEAD portion of the HTML. For example, here is a CDN for jQuery 3.3.1:

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

With this in place, you can confirm that jQuery is available and working by adding this block of JavaScript code to the script portion of the HTML:

  window.onload = function() {
    if (window.jQuery) {
        // jQuery is loaded
        alert("jQuery is working!");
    } else {
        // jQuery is not loaded
        alert("Hmm, jQuery not working.");
    }
  }

If jQuery is running, the alert will say “jQuery is working!”. Otherwise the alert will say “Hmm, jQuery not working.”. You can test this by commenting and uncommenting the jQuery CDN.

Another way to use jQuery is to download the package and call it locally rather than use a CDN. For example, on this download page:
http://jquery.com/download/

I chose the option “Download the compressed, production jQuery 3.3.1”:

Which sent me to this page:
https://code.jquery.com/jquery-3.3.1.min.js

To save the code, right click and choose “Save Page As…”:

Save this to the directory your project is in, and then call it in the HTML like this:

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

Then test to make sure it is working the same way described above.

Here is what w3schools says about jQuery:

jQuery is a lightweight, “write less, do more”, JavaScript library.

The purpose of jQuery is to make it much easier to use JavaScript on your website.

jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.

jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.

The jQuery library contains the following features:

  • HTML/DOM manipulation
  • CSS manipulation
  • HTML event methods
  • Effects and animations
  • AJAX
  • Utilities

In addition, jQuery has plugins for almost any task out there.

For more information about getting started with jQuery, see:
https://www.w3schools.com/jquery/jquery_get_started.asp