1 | # jQuery
|
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](https://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.5.1](https://blog.jquery.com/2020/05/04/jquery-3-5-1-released-fixing-a-regression/). 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.5.1.min.js"></script>
|
20 | ```
|
21 |
|
22 | #### Babel
|
23 |
|
24 | [Babel](https://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 documentation. 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](https://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](https://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/jsdom/jsdom). This can be useful for testing purposes.
|
57 |
|
58 | ```js
|
59 | const { JSDOM } = require( "jsdom" );
|
60 | const { window } = new JSDOM( "" );
|
61 | const $ = require( "jquery" )( window );
|
62 | ```
|