To include jQuery, we use a <script>
tag as follows:
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
In this example, the jQuery library is loaded from the jQuery content delivery network (CDN). A CDN is a collection of servers that can deliver content.
You must include the <script>
tag in the HTML document before you link to a JavaScript file that uses the jQuery library. The integrity
and crossorigin
properties in the example ensure the file is delivered without any third-party manipulation.
We will use jQuery methods in a JavaScript file called main.js, which we will load into index.html using a <script>
tag. We need to load the jQuery library before the main.js file. Otherwise, the computer will not understand the jQuery used in main.js.
Instructions
Copy and paste the <script>
tag from the instructions above.
Navigate to index.html. Paste the copied tag on the line before the HTML loads main.js - found near the end of the HTML document.
We are using the minified version of jQuery from the jQuery CDN.