1 # [jQuery](https://jquery.com/) — New Wave JavaScript
3 Meetings are currently held on the [matrix.org platform](https://matrix.to/#/#jquery_meeting:gitter.im).
5 Meeting minutes can be found at [meetings.jquery.org](https://meetings.jquery.org/category/core/).
7 The latest version of jQuery is available at [https://jquery.com/download/](https://jquery.com/download/).
11 | Version | Branch | Status |
12 | ------- | ---------- | -------- |
14 | 3.x | 3.x-stable | Active |
15 | 2.x | 2.x-stable | Inactive |
16 | 1.x | 1.x-stable | Inactive |
18 Once 4.0.0 final is released, the 3.x branch will continue to receive updates for a limited time. The 2.x and 1.x branches are no longer supported.
20 Commercial support for inactive versions is available from [HeroDevs](https://herodevs.com/nes).
22 Learn more about our [version support](https://jquery.com/support/).
24 ## Contribution Guides
26 In the spirit of open source software development, jQuery always encourages community code contribution. To help you get started and before you jump into writing code, be sure to read these important contribution guidelines thoroughly:
28 1. [Getting Involved](https://contribute.jquery.org/)
29 2. [Core Style Guide](https://contribute.jquery.org/style-guide/js/)
30 3. [Writing Code for jQuery Projects](https://contribute.jquery.org/code/)
32 ### References to issues/PRs
34 GitHub issues/PRs are usually referenced via `gh-NUMBER`, where `NUMBER` is the numerical ID of the issue/PR. You can find such an issue/PR under `https://github.com/jquery/jquery/issues/NUMBER`.
36 jQuery has used a different bug tracker - based on Trac - in the past, available under [bugs.jquery.com](https://bugs.jquery.com/). It is being kept in read only mode so that referring to past discussions is possible. When jQuery source references one of those issues, it uses the pattern `trac-NUMBER`, where `NUMBER` is the numerical ID of the issue. You can find such an issue under `https://bugs.jquery.com/ticket/NUMBER`.
38 ## Environments in which to use jQuery
40 - [Browser support](https://jquery.com/browser-support/)
41 - jQuery also supports Node, browser extensions, and other non-browser environments.
43 ## What you need to build your own jQuery
45 To build jQuery, you need to have the latest Node.js/npm and git 1.7 or later. Earlier versions might work, but are not supported.
47 For Windows, you have to download and install [git](https://git-scm.com/downloads) and [Node.js](https://nodejs.org/en/download/).
49 macOS users should install [Homebrew](https://brew.sh/). Once Homebrew is installed, run `brew install git` to install git,
50 and `brew install node` to install Node.js.
52 Linux/BSD users should use their appropriate package managers to install git and Node.js, or build from source
53 if you swing that way. Easy-peasy.
55 ## How to build your own jQuery
57 First, [clone the jQuery git repo](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
59 Then, enter the jquery directory, install dependencies, and run the build script:
67 The built version of jQuery will be placed in the `dist/` directory, along with a minified copy and associated map file.
69 ## Build all jQuery release files
71 To build all variants of jQuery, run the following command:
77 This will create all of the variants that jQuery includes in a release, including `jquery.js`, `jquery.slim.js`, `jquery.module.js`, and `jquery.slim.module.js` along their associated minified files and sourcemaps.
79 `jquery.module.js` and `jquery.slim.module.js` are [ECMAScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) that export `jQuery` and `$` as named exports are placed in the `dist-module/` directory rather than the `dist/` directory.
81 ## Building a Custom jQuery
83 The build script can be used to create a custom version of jQuery that includes only the modules you need.
85 Any module may be excluded except for `core`. When excluding `selector`, it is not removed but replaced with a small wrapper around native `querySelectorAll` (see below for more information).
89 To see the full list of available options for the build script, run the following:
92 npm run build -- --help
97 To exclude a module, pass its path relative to the `src` folder (without the `.js` extension) to the `--exclude` option. When using the `--include` option, the default includes are dropped and a build is created with only those modules.
99 Some example modules that can be excluded or included are:
101 - **ajax**: All AJAX functionality: `$.ajax()`, `$.get()`, `$.post()`, `$.ajaxSetup()`, `.load()`, transports, and ajax event shorthands such as `.ajaxStart()`.
102 - **ajax/xhr**: The XMLHTTPRequest AJAX transport only.
103 - **ajax/script**: The `<script>` AJAX transport only; used to retrieve scripts.
104 - **ajax/jsonp**: The JSONP AJAX transport only; depends on the ajax/script transport.
105 - **css**: The `.css()` method. Also removes **all** modules depending on css (including **effects**, **dimensions**, and **offset**).
106 - **css/showHide**: Non-animated `.show()`, `.hide()` and `.toggle()`; can be excluded if you use classes or explicit `.css()` calls to set the `display` property. Also removes the **effects** module.
107 - **deprecated**: Methods documented as deprecated but not yet removed.
108 - **dimensions**: The `.width()` and `.height()` methods, including `inner-` and `outer-` variations.
109 - **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
110 - **event**: The `.on()` and `.off()` methods and all event functionality.
111 - **event/trigger**: The `.trigger()` and `.triggerHandler()` methods.
112 - **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
113 - **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
114 - **core/ready**: Exclude the ready module if you place your scripts at the end of the body. Any ready callbacks bound with `jQuery()` will simply be called immediately. However, `jQuery(document).ready()` will not be a function and `.on("ready", ...)` or similar will not be triggered.
115 - **deferred**: Exclude jQuery.Deferred. This also excludes all modules that rely on Deferred, including **ajax**, **effects**, and **queue**, but replaces **core/ready** with **core/ready-no-deferred**.
116 - **exports/global**: Exclude the attachment of global jQuery variables ($ and jQuery) to the window.
117 - **exports/amd**: Exclude the AMD definition.
119 - **selector**: The full jQuery selector engine. When this module is excluded, it is replaced with a rudimentary selector engine based on the browser's `querySelectorAll` method that does not support jQuery selector extensions or enhanced semantics. See the [selector-native.js](https://github.com/jquery/jquery/blob/main/src/selector-native.js) file for details.
121 *Note*: Excluding the full `selector` module will also exclude all jQuery selector extensions (such as `effects/animatedSelector` and `css/hiddenVisibleSelectors`).
125 You can set the module name for jQuery's AMD definition. By default, it is set to "jquery", which plays nicely with plugins and third-party libraries, but there may be cases where you'd like to change this. Pass it to the `--amd` parameter:
128 npm run build -- --amd="custom-name"
131 Or, to define anonymously, leave the name blank.
134 npm run build -- --amd
137 ##### File name and directory
139 The default name for the built jQuery file is `jquery.js`; it is placed under the `dist/` directory. It's possible to change the file name using `--filename` and the directory using `--dir`. `--dir` is relative to the project root.
142 npm run build -- --slim --filename="jquery.slim.js" --dir="/tmp"
145 This would create a slim version of jQuery and place it under `tmp/jquery.slim.js`.
147 ##### ECMAScript Module (ESM) mode
149 By default, jQuery generates a regular script JavaScript file. You can also generate an ECMAScript module exporting `jQuery` as the default export using the `--esm` parameter:
152 npm run build -- --filename=jquery.module.js --esm
157 By default, jQuery depends on a global `window`. For environments that don't have one, you can generate a factory build that exposes a function accepting `window` as a parameter that you can provide externally (see [`README` of the published package](build/fixtures/README.md) for usage instructions). You can generate such a factory using the `--factory` parameter:
160 npm run build -- --filename=jquery.factory.js --factory
163 This option can be mixed with others like `--esm` or `--slim`:
166 npm run build -- --filename=jquery.factory.slim.module.js --factory --esm --slim --dir="/dist-module"
169 #### Custom Build Examples
171 Create a custom build using `npm run build`, listing the modules to be excluded. Excluding a top-level module also excludes its corresponding directory of modules.
173 Exclude all **ajax** functionality:
176 npm run build -- --exclude=ajax
179 Excluding **css** removes modules depending on CSS: **effects**, **offset**, **dimensions**.
182 npm run build -- --exclude=css
185 Exclude a bunch of modules (`-e` is an alias for `--exclude`):
188 npm run build -- -e ajax/jsonp -e css -e deprecated -e dimensions -e effects -e offset -e wrap
191 There is a special alias to generate a build with the same configuration as the official jQuery Slim build:
194 npm run build -- --filename=jquery.slim.js --slim
197 Or, to create the slim build as an esm module:
200 npm run build -- --filename=jquery.slim.module.js --slim --esm
203 *Non-official custom builds are not regularly tested. Use them at your own risk.*
205 ## Running the Unit Tests
207 Make sure you have the necessary dependencies:
213 Start `npm start` to auto-build jQuery as you work:
219 Run the unit tests with a local server that supports PHP. Ensure that you run the site from the root directory, not the "test" directory. No database is required. Pre-configured php local servers are available for Windows and Mac. Here are some options:
221 - Windows: [WAMP download](https://www.wampserver.com/en/)
222 - Mac: [MAMP download](https://www.mamp.info/en/downloads/)
223 - Linux: [Setting up LAMP](https://www.linux.com/training-tutorials/easy-lamp-server-installation/)
224 - [Mongoose (most platforms)](https://code.google.com/p/mongoose/)
228 As the source code is handled by the Git version control system, it's useful to know some features used.
232 If you want to purge your working directory back to the status of upstream, the following commands can be used (remember everything you've worked on is gone after these):
235 git reset --hard upstream/main
241 For feature/topic branches, you should always use the `--rebase` flag to `git pull`, or if you are usually handling many temporary "to be in a github pull request" branches, run the following to automate this:
244 git config branch.autosetuprebase local
247 (see `man git-config` for more information)
249 ### Handling merge conflicts
251 If you're getting merge conflicts when merging, instead of editing the conflicted files manually, you can use the feature
252 `git mergetool`. Even though the default tool `xxdiff` looks awful/old, it's rather useful.
254 The following are some commands that can be used there:
256 - `Ctrl + Alt + M` - automerge as much as possible
257 - `b` - jump to next merge conflict
258 - `s` - change the order of the conflicted lines
260 - `left mouse button` - mark a block to be the winner
261 - `middle mouse button` - mark a line to be the winner
265 ## [QUnit](https://api.qunitjs.com) Reference
270 expect( numAssertions );
275 *Note*: QUnit's eventual addition of an argument to stop/start is ignored in this test suite so that start and stop can be passed as callbacks without worrying about their parameters.
280 ok( value, [message] );
281 equal( actual, expected, [message] );
282 notEqual( actual, expected, [message] );
283 deepEqual( actual, expected, [message] );
284 notDeepEqual( actual, expected, [message] );
285 strictEqual( actual, expected, [message] );
286 notStrictEqual( actual, expected, [message] );
287 throws( block, [expected], [message] );
290 ## Test Suite Convenience Methods Reference
292 See [test/data/testinit.js](https://github.com/jquery/jquery/blob/main/test/data/testinit.js).
294 ### Returns an array of elements with the given IDs
303 q( "main", "foo", "bar" );
305 => [ div#main, span#foo, input#bar ]
308 ### Asserts that a selection matches the given IDs
311 t( testName, selector, [ "array", "of", "ids" ] );
317 t("Check for something", "//[a]", ["foo", "bar"]);
320 ### Fires a native DOM event without going through jQuery
323 fireNative( node, eventType );
329 fireNative( jQuery( "#elem" )[ 0 ], "click" );
332 ### Add random number to url to stop caching
343 => "data/index.html?10538358428943"
346 url( "mock.php?foo=bar" );
348 => "data/mock.php?foo=bar&10538358345554"
351 ### Run tests in an iframe
353 Some tests may require a document other than the standard test fixture, and
354 these can be run in a separate iframe. The actual test code and assertions
355 remain in jQuery's main test files; only the minimal test fixture markup
356 and setup code should be placed in the iframe file.
359 testIframe( testName, fileName,
360 function testCallback(
361 assert, jQuery, window, document,
362 [ additional args ] ) {
367 This loads a page, constructing a url with fileName `"./data/" + fileName`.
368 The iframed page determines when the callback occurs in the test by
369 including the "/test/data/iframeTest.js" script and calling
370 `startIframeTest( [ additional args ] )` when appropriate. Often this
371 will be after either document ready or `window.onload` fires.
373 The `testCallback` receives the QUnit `assert` object created by `testIframe`
374 for this test, followed by the global `jQuery`, `window`, and `document` from
375 the iframe. If the iframe code passes any arguments to `startIframeTest`,
376 they follow the `document` argument.
380 If you have any questions, please feel free to ask on the
381 [Developing jQuery Core forum](https://forum.jquery.com/developing-jquery-core) or in #jquery on [libera](https://web.libera.chat/).