Including jQuery In Web Pages

Consider jQuery a Javascript script file that should be loaded in all your HTML pages. This file should be included above all your javascript code to access the jQuery functions.

Not including the jQuery file will result in a lot of Javascript errors. So make sure the jQuery file is loaded before all Javascript code.

Install jQuery in HTML

Including jQuery is very simple. You can either download the library and load it from your local directory or use the online version.

Download jQuery

First download jQuery library from the official website in your project directory. In our project tree, we have an assets folder inside which we have a js folder where we’ll store all our project’s Javascript files including jQuery library.


Download jQuery

Load the jQuery file just before the closing body tag.

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

Install CDN hosted library

The second option to include jQuery is to load it from CDN. CDN hosted files load faster and that makes your website load faster no matter where the user is located in the world.

<script src="https://ajax.googleapis.com/ajax/libs/d3js/5.7.0/d3.min.js"></script>

Test File

<!DOCTYPE html>
  <title>jQuery Test File</title>

<h1>Welcome to jQuery lessons</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

{{-- jquery cdn --}}
<script src="https://ajax.googleapis.com/ajax/libs/d3js/5.7.0/d3.min.js"></script>



Related Articles