3.7.1 • Published 25 days ago

jquery v3.7.1

Weekly downloads
4,025,819
License
MIT
Repository
github
Last release
25 days ago

jQuery

jQuery is a fast, small, and feature-rich JavaScript library.

For information on how to get started and how to use jQuery, please see jQuery's documentation. For source files and issues, please visit the jQuery repo.

If upgrading, please see the blog post for 4.0.0-beta. This includes notable differences from the previous version and a more readable changelog.

Including jQuery

Below are some of the most common ways to include jQuery.

Browser

Script tag

<script src="https://code.jquery.com/jquery-4.0.0-beta.min.js"></script>

or, to use the jQuery ECMAScript module:

<script type="module">
	import { $ } from "https://code.jquery.com/jquery-4.0.0-beta.module.min.js";
</script>

or:

<script type="module">
	import { jQuery } from "https://code.jquery.com/jquery-4.0.0-beta.module.min.js";
</script>

All jQuery modules export named $ & jQuery tokens; the further examples will just show $. The default import also works:

<script type="module">
	import $ from "https://code.jquery.com/jquery-4.0.0-beta.module.min.js";
</script>

However, named imports provide better interoperability across tooling and are therefore recommended.

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:

<script src="https://code.jquery.com/jquery-4.0.0-beta.slim.min.js"></script>

or as a module:

<script type="module">
	import { $ } from "https://code.jquery.com/jquery-4.0.0-beta.module.slim.min.js";
</script>

Import maps

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">:

<script type="importmap">
	{
		"imports": {
			"jquery": "https://code.jquery.com/jquery-4.0.0-beta.module.min.js",
			"jquery/slim": "https://code.jquery.com/jquery-4.0.0-beta.module.slim.min.js"
		}
	}
</script>

Now, the following will work to get the full version:

<script type="module">
	import { $ } from "jquery";
	// Use $ here
</script>

and the following to get the slim one:

<script type="module">
	import { $ } from "jquery/slim";
	// Use $ here
</script>

The advantage of these specific mappings is they match the ones embedded in the jQuery npm package, providing better interoperability between the environments.

You can also use jQuery from npm even in the browser setup. Read along for more details.

Using jQuery from npm

There are several ways to use jQuery from npm. One is to use a build tool like Webpack, Browserify or Babel. For more information on using these tools, please refer to the corresponding project's documentation.

Another way is to use jQuery directly in Node.js. See the Node.js pre-requisites section for more details on the Node.js-specific part of this.

To install the jQuery npm package, invoke:

npm install jquery

In the script, including jQuery will usually look like this:

import { $ } from "jquery";

If you need to use jQuery in a file that's not an ECMAScript module, you can use the CommonJS syntax:

const $ = require( "jquery" );

Individual modules

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.

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.

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.

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.

Example usage:

import { $ } from "jquery/src/css.js"; // adds the `.css()` method
import "jquery/src/event.js"; // adds the `.on()` method; pulls "selector" as a dependency
$( ".toggle" ).on( "click", function() {
	$( this ).css( "color", "red" );
} );

AMD (Asynchronous Module Definition)

AMD is a module format built for the browser. For more information, we recommend require.js' documentation.

define( [ "jquery" ], function( $ ) {

} );

Node.js doesn't understand AMD natively so this method is mostly used in a browser setup.

Node.js pre-requisites

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. This can be useful for testing purposes.

For Node-based environments that don't have a global window, jQuery exposes a dedicated jquery/factory entry point.

To import jQuery using this factory, use the following:

import { JSDOM } from "jsdom";
const { window } = new JSDOM( "" );
import { jQueryFactory } from "jquery/factory";
const $ = jQueryFactory( window );

or, if you use require:

const { JSDOM } = require( "jsdom" );
const { window } = new JSDOM( "" );
const { jQueryFactory } = require( "jquery/factory" );
const $ = jQueryFactory( window );

Slim build in Node.js

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.

ymapboxvue-pnotifywcmschatroomwithcoin-sdkytd-vue-gprszheshiwo-jintianshanfgfmlxcustomcomponentfront-template@catena-x/portal-shared-components-test@yykj/ak-vue-components@ytd/fe-vue@ytd/fe-vue-zs@ytd/fiber-tool-front@ytd/lite-vue@ytd/odn-tool-front@aleen42/editor@arunkeshavareddy/dc-common@ljmarquezge2y/worldpay-spartacus@shooktea/vuestrap@narupo/popmsg@dacoto/ui-dashboard@hyperblob/magic-tableab-pdf-reader-exampleabwaanchor-listanchor-popupadminkit-proalarmruaccessible-bootstrap-carouselatx-filemanagerc3ppceyenneceyenne2020-fo-base@borderfreefinancial/revo-consumer@borderfreefinancial/revo-core@borderfreefinancial/revo-core-api@borderfreefinancial/revo-web-video-test@borderfreefinancial/dev-revo-consumer-lite-testing1-local@borderfreefinancial/elements-react@borderfreefinancial/dev-revo-consumer-lite-testing1@grafana/ui@edifice.io/mindplotciao-vue-popupcoveo-interface-editordeckgl-webpack-exampledftdev@c8y/ng1-modules@instructure/quiz-interactions@crawlee/playwright@crawlee/puppeteer@rafaelcalpena/re-use@zaneray/cornerstonevue-plug-cylshauxin-cli@webx/bootstrap@webx/jquery@jadex/webx-bootstrap@jadex/webx-jqueryxncomponentsgg-package@amn31/ma-ng-data-gridlou-dbharavan-react-componentscollageplusreact-janus-live-streamtest-systemrn-aht-jitsi-meetwl_adcollaborate-space-for-webti-tablesawsidenoderlab3akibardinlab3kibardinheadless-chrome-crawler-testllamatorials-bootstrap@jesswu1551/jquery-contextmenu@jesswu1551/jquery-contextmenu-xxx@fengyinchao/moduleaw222w111w123w456vf-123react-calculator-testpatient-browserselect_allstacksofcashxuirecorderplusnpm-jquery-table-bootstrap@hivecloud/angular-ui-libng-selectize-v2strapi-plugin-survey-jstsemap-visualizemiaov-reactmiaov-shanghaimiaov20181220@wjghj-project/inpageeditusers-webng-pointfront-core-lib
4.0.0-beta

25 days ago

3.7.1

6 months ago

3.7.0

10 months ago

3.6.4

12 months ago

3.6.2

1 year ago

3.6.3

1 year ago

3.6.1

2 years ago

3.6.0

3 years ago

3.5.1

4 years ago

3.5.0

4 years ago

3.4.1

5 years ago

3.4.0

5 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.1

7 years ago

3.1.0

8 years ago

3.0.0

8 years ago

3.0.0-rc1

8 years ago

2.2.4

8 years ago

1.12.4

8 years ago

2.2.3

8 years ago

1.12.3

8 years ago

2.2.2

8 years ago

1.12.2

8 years ago

2.2.1

8 years ago

1.12.1

8 years ago

3.0.0-beta1

8 years ago

2.2.0

8 years ago

1.12.0

8 years ago

3.0.0-alpha1

9 years ago

1.11.3

9 years ago

2.1.4

9 years ago

2.1.3

9 years ago

1.11.2

9 years ago

2.1.2

9 years ago

1.9.1

10 years ago

1.11.1

10 years ago

2.1.1

10 years ago

1.11.1-rc2

10 years ago

2.1.1-rc2

10 years ago

1.11.1-rc1

10 years ago

2.1.1-rc1

10 years ago

1.11.1-beta1

10 years ago

2.1.1-beta1

10 years ago

2.1.0

10 years ago

1.11.0

10 years ago

2.1.0-rc1

10 years ago

1.11.0-rc1

10 years ago

1.11.0-pre

10 years ago

1.11.0-beta3

10 years ago

2.1.0-beta3

10 years ago

2.1.0-beta2

10 years ago

1.8.3

11 years ago

1.8.2

11 years ago

1.7.3

12 years ago

1.7.2

12 years ago

1.6.3

12 years ago

1.6.2

13 years ago

1.5.1

13 years ago