You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For information on how to get started and how to use jQuery, please see [jQuery's documentation](https://api.jquery.com/).
6
6
For source files and issues, please visit the [jQuery repo](https://github.com/jquery/jquery).
7
7
8
-
If upgrading, please see the [blog post for 4.0.0](https://blog.jquery.com/2026/01/17/jquery-4-0-0/). This includes notable differences from the previous version and a more readable changelog.
8
+
If upgrading, please see the [blog post for 3.7.1](https://blog.jquery.com/2023/08/28/jquery-3-7-1-released-reliable-table-row-dimensions/). This includes notable differences from the previous version and a more readable changelog.
9
9
10
10
## Including jQuery
11
11
@@ -16,133 +16,24 @@ Below are some of the most common ways to include jQuery.
However, named imports provide better interoperability across tooling and are therefore recommended.
47
-
48
-
Sometimes you don’t need AJAX, or you prefer to use one of the many standalone libraries that focus on AJAX requests. And often it is simpler to use a combination of CSS, class manipulation or the Web Animations API. Similarly, many projects opt into relying on native browser promises instead of jQuery Deferreds. Along with the regular version of jQuery that includes the `ajax`, `callbacks`, `deferred`, `effects` & `queue` modules, we’ve released a “slim” version that excludes these modules. You can load it as a regular script:
To avoid repeating long import paths that change on each jQuery release, you can use import maps - they are now supported in every modern browser. Put the following script tag before any `<script type="module">`:
Now, the following will work to get the full version:
78
-
79
-
```html
80
-
<scripttype="module">
81
-
import { $ } from"jquery";
82
-
// Use $ here
83
-
</script>
84
-
```
85
-
86
-
and the following to get the slim one:
87
-
88
-
```html
89
-
<scripttype="module">
90
-
import { $ } from"jquery/slim";
91
-
// Use $ here
92
-
</script>
93
-
```
94
-
95
-
The advantage of these specific mappings is they match the ones embedded in the jQuery npm package, providing better interoperability between the environments.
96
-
97
-
You can also use jQuery from npm even in the browser setup. Read along for more details.
98
-
99
-
### Using jQuery from npm
100
-
101
-
There are several ways to use jQuery from npm. One is to use a build tool like [Webpack](https://webpack.js.org/), [Browserify](https://browserify.org/) or [Babel](https://babeljs.io/). For more information on using these tools, please refer to the corresponding project's documentation.
102
-
103
-
Another way is to use jQuery directly in Node.js. See the [Node.js pre-requisites](#nodejs-pre-requisites) section for more details on the Node.js-specific part of this.
104
-
105
-
To install the jQuery npm package, invoke:
106
-
107
-
```sh
108
-
npm install jquery
109
-
```
110
-
111
-
In the script, including jQuery will usually look like this:
24
+
There are several ways to use [Webpack](https://webpack.js.org/), [Browserify](http://browserify.org/) or [Babel](https://babeljs.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:
112
25
113
26
```js
114
-
import{ $ }from"jquery";
27
+
import$from"jquery";
115
28
```
116
29
117
30
If you need to use jQuery in a file that's not an ECMAScript module, you can use the CommonJS syntax:
118
31
119
32
```js
120
-
const$=require( "jquery" );
33
+
var $ =require( "jquery" );
121
34
```
122
35
123
-
The CommonJS module _does not_ expose named `$` & `jQuery` exports.
124
-
125
-
#### Individual modules
126
-
127
-
jQuery is authored in ECMAScript modules; it's also possible to use them directly. They are contained in the `src/` folder; inspect the package contents to see what's there. Full file names are required, including the `.js` extension.
128
-
129
-
Be aware that this is an advanced & low-level interface, and we don't consider it stable, even between minor or patch releases - this is especially the case for modules in subdirectories or `src/`. If you rely on it, verify your setup before updating jQuery.
130
-
131
-
All top-level modules, i.e. files directly in the `src/` directory export jQuery. Importing multiple modules will all attach to the same jQuery instance.
132
-
133
-
Remember that some modules have other dependencies (e.g. the `event` module depends on the `selector` one) so in some cases you may get more than you expect.
134
-
135
-
Example usage:
136
-
137
-
```js
138
-
import { $ } from"jquery/src/css.js"; // adds the `.css()` method
139
-
import"jquery/src/event.js"; // adds the `.on()` method; pulls "selector" as a dependency
140
-
$( ".toggle" ).on( "click", function() {
141
-
$( this ).css( "color", "red" );
142
-
} );
143
-
```
144
-
145
-
### AMD (Asynchronous Module Definition)
36
+
#### AMD (Asynchronous Module Definition)
146
37
147
38
AMD is a module format built for the browser. For more information, we recommend [require.js' documentation](https://requirejs.org/docs/whyamd.html).
Node.js doesn't understand AMD natively so this method is mostly used in a browser setup.
156
-
157
-
### Node.js pre-requisites
158
-
159
-
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.
46
+
### Node
160
47
161
-
For Node-based environments that don't have a global `window`, jQuery exposes a dedicated `jquery/factory` entry point.
48
+
To include jQuery in [Node](https://nodejs.org/), first install with npm.
162
49
163
-
To `import` jQuery using this factory, use the following:
164
-
165
-
```js
166
-
import { JSDOM } from"jsdom";
167
-
const { window } =newJSDOM( "" );
168
-
import { jQueryFactory } from"jquery/factory";
169
-
const$=jQueryFactory( window );
50
+
```sh
51
+
npm install jquery
170
52
```
171
53
172
-
or, if you use `require`:
54
+
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.
To use the slim build of jQuery in Node.js, use `"jquery/slim"` instead of `"jquery"` in both `require` or `import` calls above. To use the slim build in Node.js with factory mode, use `jquery/factory-slim` instead of `jquery/factory`.
0 commit comments