| commit | author | age | ||
| 83c3f6 | 1 | # jQuery |
| SP | 2 | |
| 3 | > jQuery is a fast, small, and feature-rich JavaScript library. | |
| 4 | ||
| 5 | For information on how to get started and how to use jQuery, please see [jQuery's documentation](http://api.jquery.com/). | |
| 6 | For source files and issues, please visit the [jQuery repo](https://github.com/jquery/jquery). | |
| 7 | ||
| 8 | If upgrading, please see the [blog post for 3.3.1](https://blog.jquery.com/2017/03/20/jquery-3.3.1-now-available/). This includes notable differences from the previous version and a more readable changelog. | |
| 9 | ||
| 10 | ## Including jQuery | |
| 11 | ||
| 12 | Below are some of the most common ways to include jQuery. | |
| 13 | ||
| 14 | ### Browser | |
| 15 | ||
| 16 | #### Script tag | |
| 17 | ||
| 18 | ```html | |
| 19 | <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> | |
| 20 | ``` | |
| 21 | ||
| 22 | #### Babel | |
| 23 | ||
| 24 | [Babel](http://babeljs.io/) is a next generation JavaScript compiler. One of the features is the ability to use ES6/ES2015 modules now, even though browsers do not yet support this feature natively. | |
| 25 | ||
| 26 | ```js | |
| 27 | import $ from "jquery"; | |
| 28 | ``` | |
| 29 | ||
| 30 | #### Browserify/Webpack | |
| 31 | ||
| 32 | There are several ways to use [Browserify](http://browserify.org/) and [Webpack](https://webpack.github.io/). For more information on using these tools, please refer to the corresponding project's documention. In the script, including jQuery will usually look like this... | |
| 33 | ||
| 34 | ```js | |
| 35 | var $ = require("jquery"); | |
| 36 | ``` | |
| 37 | ||
| 38 | #### AMD (Asynchronous Module Definition) | |
| 39 | ||
| 40 | AMD is a module format built for the browser. For more information, we recommend [require.js' documentation](http://requirejs.org/docs/whyamd.html). | |
| 41 | ||
| 42 | ```js | |
| 43 | define(["jquery"], function($) { | |
| 44 | ||
| 45 | }); | |
| 46 | ``` | |
| 47 | ||
| 48 | ### Node | |
| 49 | ||
| 50 | To include jQuery in [Node](nodejs.org), first install with npm. | |
| 51 | ||
| 52 | ```sh | |
| 53 | npm install jquery | |
| 54 | ``` | |
| 55 | ||
| 56 | For jQuery to work in Node, a window with a document is required. Since no such window exists natively in Node, one can be mocked by tools such as [jsdom](https://github.com/tmpvar/jsdom). This can be useful for testing purposes. | |
| 57 | ||
| 58 | ```js | |
| 59 | require("jsdom").env("", function(err, window) { | |
| 60 | if (err) { | |
| 61 | console.error(err); | |
| 62 | return; | |
| 63 | } | |
| 64 | ||
| 65 | var $ = require("jquery")(window); | |
| 66 | }); | |
| 67 | ``` | |