//INIT: Using libraries

<New code>

jQuery //INIT: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
— loads jQuery library

jQuery and using libraries

Javascript is a full and capable language with pretty good (although not perfect) fundamentals. It compares well with other languages. However, while it is possible to do a great many things with Javascript, it is often a lot of work to do it. Programmers will often create sets of functions and procedures that will automate repetitive, programming intensive tasks. For example, if you are constantly programming maps into your programs, you will want to make one great set of code that you can then borrow and use in many of your other programs.

This set of code is called a library. Code libraries can share a set of useful programming functions to more than one program. I have made dozens of code libraries in the past to support large or repetitive projects. For example, if I am constantly validating user security among a couple hundred web pages, I will write one shared library that will help apply security consistently and with less effort. Writing one library to use with many programs means less work and less repetition.

Introducing jQuery

jQuery is a set of libraries developed by Google to help make and run Google web apps. The home of the jQuery community is at: jquery.com.

jQuery's libraries allow you to do things like:

In this lesson, we will be using jQuery to simplify animation.

Linking the jQuery library to your code

In the head of your document, you can add the jQuery library by adding this before your <script>:

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

Every time your page is loaded, it will now contact a google webserver, and download the library so that your browser can use it. This slows down the load speed of your page a little. Some people download their own copy of the library and point the <script src="..."> to their downloaded copy. Sometimes this actually slows things down more — it all depends on internet traffic and server power.

Learn more