You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

4 years ago
  1. # jQuery
  2. > jQuery is a fast, small, and feature-rich JavaScript library.
  3. For information on how to get started and how to use jQuery, please see [jQuery's documentation](http://api.jquery.com/).
  4. For source files and issues, please visit the [jQuery repo](https://github.com/jquery/jquery).
  5. If upgrading, please see the [blog post for 3.2.1](https://blog.jquery.com/2017/03/20/jquery-3-2-1-now-available/). This includes notable differences from the previous version and a more readable changelog.
  6. ## Including jQuery
  7. Below are some of the most common ways to include jQuery.
  8. ### Browser
  9. #### Script tag
  10. ```html
  11. <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  12. ```
  13. #### Babel
  14. [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.
  15. ```js
  16. import $ from "jquery";
  17. ```
  18. #### Browserify/Webpack
  19. 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...
  20. ```js
  21. var $ = require("jquery");
  22. ```
  23. #### AMD (Asynchronous Module Definition)
  24. AMD is a module format built for the browser. For more information, we recommend [require.js' documentation](http://requirejs.org/docs/whyamd.html).
  25. ```js
  26. define(["jquery"], function($) {
  27. });
  28. ```
  29. ### Node
  30. To include jQuery in [Node](nodejs.org), first install with npm.
  31. ```sh
  32. npm install jquery
  33. ```
  34. 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.
  35. ```js
  36. require("jsdom").env("", function(err, window) {
  37. if (err) {
  38. console.error(err);
  39. return;
  40. }
  41. var $ = require("jquery")(window);
  42. });
  43. ```