diff --git a/.github/configs/hydra-config.json b/.github/configs/hydra-config.json index 3d367e7b..2173722b 100644 --- a/.github/configs/hydra-config.json +++ b/.github/configs/hydra-config.json @@ -1,5 +1,10 @@ { + "//": [ + "2023-05: twitter.com serves broken redirect-loop", + "2025-04: The oembed endpoint responds HTTP 429 Too Many Requests too often; perhaps because almost every page links to one" + ], "exclude_scheme_prefixes": [ - "https://twitter.com/" + "https://twitter.com/", + "https://api.jquery.com/wp-json/oembed/1.0/embed" ] } diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..aa2f7456 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: monthly + + # Group all dependabot version update PRs into one + groups: + github-actions: + applies-to: version-updates + patterns: + - "*" diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index d74cb10f..6b194c62 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -3,8 +3,9 @@ name: Node.js CI on: - - push - - pull_request + pull_request: + push: + branches-ignore: "dependabot/**" jobs: build: @@ -16,13 +17,16 @@ jobs: node-version: [18.x, 20.x] steps: - - name: Install xmllint - run: sudo apt-get install -y libxml2-utils - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm ci - - run: npm test + - name: Checkout + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - name: Update apt-get cache + run: sudo apt-get update + - name: Install xmllint + run: sudo apt-get install -y libxml2-utils + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm test diff --git a/.github/workflows/spider-check.yaml b/.github/workflows/spider-check.yaml index 8640892f..ac635ea4 100644 --- a/.github/workflows/spider-check.yaml +++ b/.github/workflows/spider-check.yaml @@ -9,22 +9,22 @@ on: push: paths: - .github/workflows/spider-check.yaml + - .github/configs/hydra-config.json pull_request: paths: - .github/workflows/spider-check.yaml + - .github/configs/hydra-config.json jobs: spider-check: if: ${{ github.repository_owner == 'jquery' }} # skip on forks - env: - MY_SITE: https://api.jquery.com runs-on: ubuntu-latest env: # Site address to crawl MY_SITE: https://api.jquery.com steps: - - name: Checkout repo - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Run hydra-link-checker run: | diff --git a/.github/workflows/typesense.yaml b/.github/workflows/typesense.yaml index da194255..c9698275 100644 --- a/.github/workflows/typesense.yaml +++ b/.github/workflows/typesense.yaml @@ -16,7 +16,8 @@ jobs: if: ${{ github.repository_owner == 'jquery' }} # skip on forks runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Docsearch Scraper shell: bash run: | diff --git a/.nvmrc b/.nvmrc index f599e28b..3c032078 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -10 +18 diff --git a/categories.xml b/categories.xml index 2f408651..0fded172 100644 --- a/categories.xml +++ b/categories.xml @@ -37,60 +37,83 @@ - - - - - - - - - - - - + + + @@ -326,199 +349,287 @@ var files = event.originalEvent.dataTransfer.files; - - - - - - - - - - - - - - - + - + - + + + + diff --git a/config-sample.json b/config-sample.json index a62b85f2..2a56329c 100644 --- a/config-sample.json +++ b/config-sample.json @@ -1,5 +1,5 @@ { - "url": "vagrant.api.jquery.com", - "username": "admin", - "password": "secret" + "url": "http://local.api.jquery.com", + "username": "dev", + "password": "dev" } diff --git a/entries/ajaxComplete-shorthand.xml b/entries/ajaxComplete-shorthand.xml index 8e9cc6bf..3f44abc1 100644 --- a/entries/ajaxComplete-shorthand.xml +++ b/entries/ajaxComplete-shorthand.xml @@ -1,5 +1,5 @@ - + .ajaxComplete() Register a handler to be called when Ajax requests complete. This is an AjaxEvent. diff --git a/entries/ajaxError-shorthand.xml b/entries/ajaxError-shorthand.xml index c1794365..f36ac54a 100644 --- a/entries/ajaxError-shorthand.xml +++ b/entries/ajaxError-shorthand.xml @@ -1,5 +1,5 @@ - + .ajaxError() Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event. diff --git a/entries/ajaxSend-shorthand.xml b/entries/ajaxSend-shorthand.xml index 37d39222..a9ae031e 100644 --- a/entries/ajaxSend-shorthand.xml +++ b/entries/ajaxSend-shorthand.xml @@ -1,5 +1,5 @@ - + .ajaxSend() Attach a function to be executed before an Ajax request is sent. This is an Ajax Event. diff --git a/entries/ajaxStart-shorthand.xml b/entries/ajaxStart-shorthand.xml index 496152b3..51b2fc9e 100644 --- a/entries/ajaxStart-shorthand.xml +++ b/entries/ajaxStart-shorthand.xml @@ -1,5 +1,5 @@ - + .ajaxStart() Register a handler to be called when the first Ajax request begins. This is an Ajax Event. diff --git a/entries/ajaxStop-shorthand.xml b/entries/ajaxStop-shorthand.xml index d5fe7f30..78121657 100644 --- a/entries/ajaxStop-shorthand.xml +++ b/entries/ajaxStop-shorthand.xml @@ -1,5 +1,5 @@ - + .ajaxStop() Register a handler to be called when all Ajax requests have completed. This is an Ajax Event. diff --git a/entries/ajaxSuccess-shorthand.xml b/entries/ajaxSuccess-shorthand.xml index 95fa6e0e..a9e54335 100644 --- a/entries/ajaxSuccess-shorthand.xml +++ b/entries/ajaxSuccess-shorthand.xml @@ -1,5 +1,5 @@ - + .ajaxSuccess() Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event. diff --git a/entries/ajaxSuccess.xml b/entries/ajaxSuccess.xml index e92a1269..8824a621 100644 --- a/entries/ajaxSuccess.xml +++ b/entries/ajaxSuccess.xml @@ -55,7 +55,7 @@ $( document ).on( "ajaxSuccess", function( event, xhr, settings ) { Show a message when an Ajax request completes successfully. diff --git a/entries/attr.xml b/entries/attr.xml index 03baf91c..ac3e5a1b 100644 --- a/entries/attr.xml +++ b/entries/attr.xml @@ -26,7 +26,7 @@

Attributes vs. Properties

The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.

For example, selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelected should be retrieved and set with the .prop() method. Prior to jQuery 1.6, these properties were retrievable with the .attr() method, but this was not within the scope of attr. These do not have corresponding attributes and are only properties.

-

Concerning boolean attributes, consider a DOM element defined by the HTML markup <input type="checkbox" checked="checked" />, and assume it is in a JavaScript variable named elem:

+

Concerning boolean attributes, consider a DOM element defined by the HTML markup <input type="checkbox" checked="" />, and assume it is in a JavaScript variable named elem:

- + + + + + @@ -131,6 +138,7 @@ The title of the emphasis is:
+ @@ -142,7 +150,8 @@ The title of the emphasis is:
- A value to set for the attribute. If null, the specified attribute will be removed (as in .removeAttr()). + + A value to set for the attribute. If null, the specified attribute will be removed (as in .removeAttr()). Non-ARIA attributes can also be removed by passing false.
@@ -162,7 +171,7 @@ The title of the emphasis is:
- +
@@ -188,6 +197,11 @@ $( "#greatphoto" ).attr({ });

When setting multiple attributes, the quotes around attribute names are optional.

+

Removing an attribute

+

To remove an attribute, either call .attr( name, null ) or use .removeAttr( name ). For non-ARIA attributes, in jQuery 4.0+ you can also call .attr( name, false ).

+
+

Note: Because ARIA attributes frequently associate behavior with "false" values that differs from attribute absence, passing false as the value for an attribute whose name starts with "aria-…" will stringify that value to "false" rather than remove the attribute. To guarantee removal of an attribute, use the .removeAttr() method or provide null as the value to the .attr() setter.

+

WARNING: When setting the 'class' attribute, you must always use quotes!

Note: Attempting to change the type attribute on an input or button element created via document.createElement() will throw an exception on Internet Explorer 8 or older.

@@ -273,5 +287,6 @@ $( "img" ).attr( "src", function() { + diff --git a/entries/css.xml b/entries/css.xml index 7d6bd56e..85a304e8 100644 --- a/entries/css.xml +++ b/entries/css.xml @@ -108,6 +108,7 @@ $( "div" ).on( "click", function() { + @@ -146,7 +147,15 @@ $( "div" ).on( "click", function() {

As with the .prop() method, the .css() method makes setting properties of elements quick and easy. This method can take either a property name and value as separate parameters, or a single object of key-value pairs.

Also, jQuery can equally interpret the CSS and DOM formatting of multiple-word properties. For example, jQuery understands and returns the correct value for both .css({ "background-color": "#ffe", "border-left": "5px solid #ccc" }) and .css({backgroundColor: "#ffe", borderLeft: "5px solid #ccc" }). Notice that with the DOM notation, quotation marks around the property names are optional, but with CSS notation they're required due to the hyphen in the name.

-

When a number is passed as the value, jQuery will convert it to a string and add px to the end of that string. If the property requires units other than px, convert the value to a string and add the appropriate units before calling the method.

+

In jQuery 3.x or older, when a number is passed as the value, jQuery will convert it to a string and add px to the end of that string. However, there are exceptions. px is not added to keys of jQuery.cssNumber If the property requires units other than px, convert the value to a string and add the appropriate units before calling the method.

+

In jQuery 4.0 or newer, when a number is passed as the value, jQuery will only convert it to a string and add px to the end of that string for a limited set of properties - mostly related to width, height, border, margin & padding; the full list:

+
    +
  • setting the element position: top, right, bottom, left
  • +
  • setting the element dimensions: width, height, min-width, min-height, max-width, max-height
  • +
  • padding-related: padding, padding-top, padding-right, padding-bottom, padding-left
  • +
  • margin-related: margin, margin-top, margin-right, margin-bottom, margin-left
  • +
  • border-related: border, border-width, border-top, border-top-width, border-right, border-right-width, border-bottom, border-bottom-width, border-left, border-left-width
  • +

When using .css() as a setter, jQuery modifies the element's style property. For example, $( "#mydiv" ).css( "color", "green" ) is equivalent to document.getElementById( "mydiv" ).style.color = "green". Setting the value of a style property to an empty string — e.g. $( "#mydiv" ).css( "color", "" ) — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .css() method, or through direct DOM manipulation of the style property. As a consequence, the element's style for that property will be restored to whatever value was applied. So, this method can be used to cancel any style modification you have previously performed. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or <style> element. Warning: one notable exception is that, for IE 8 and below, removing a shorthand property such as border or background will remove that style entirely from the element, regardless of what is set in a stylesheet or <style> element.

Note: .css() doesn't support !important declarations. So, the statement $( "p" ).css( "color", "red !important" ) does not turn the color of all paragraphs in the page to red as of jQuery 3.6.0. Do not depend on that not working, though, as a future version of jQuery may add support for such declarations. It's strongly advised to use classes instead; otherwise use a jQuery plugin.

As of jQuery 1.8, the .css() setter will automatically take care of prefixing the property name. For example, take .css( "user-select", "none" ) in Chrome/Safari will set it as -webkit-user-select, Firefox will use -moz-user-select, and IE10 will use -ms-user-select.

@@ -286,5 +295,6 @@ $( "div" ).on( "click", function() { +
diff --git a/entries/html.xml b/entries/html.xml index 0eae2f74..1a29d361 100644 --- a/entries/html.xml +++ b/entries/html.xml @@ -118,7 +118,7 @@ $( "div.demo-container" ).html(function() { });

Given a document with six paragraphs, this example will set the HTML of <div class="demo-container"> to <p>All new content for <em>6 paragraphs!</em></p>.

-

This method uses the browser's innerHTML property. Some browsers may not generate a DOM that exactly replicates the HTML source provided. For example, Internet Explorer prior to version 8 will convert all href properties on links to absolute URLs, and Internet Explorer prior to version 9 will not correctly handle HTML5 elements without the addition of a separate compatibility layer.

+

This method uses the browser's innerHTML property. Some browsers may not generate a DOM that exactly replicates the HTML source provided. For example, Internet Explorer prior to version 8 will convert all href properties on links to absolute URLs, and Internet Explorer prior to version 9 will not correctly handle HTML5 elements without the addition of a separate compatibility layer.

To set the content of a <script> element, which does not contain HTML, use the .text() method and not .html().

Note: In Internet Explorer up to and including version 9, setting the text content of an HTML element may corrupt the text nodes of its children that are being removed from the document as a result of the operation. If you are keeping references to these DOM elements and need them to be unchanged, use .empty().html( string ) instead of .html(string) so that the elements are removed from the document before the new string is assigned to the element.

diff --git a/entries/jQuery.Deferred.exceptionHook.xml b/entries/jQuery.Deferred.exceptionHook.xml new file mode 100644 index 00000000..db6c3226 --- /dev/null +++ b/entries/jQuery.Deferred.exceptionHook.xml @@ -0,0 +1,34 @@ + + + jQuery.Deferred.exceptionHook() + + 3.0 + + Handle errors produced by Deferreds. + +

This API is called every time an error is thrown inside Deferreds. By default, it only warns about errors that are more likely to be programmer errors than errors thrown due to application logic. This includes errors like SyntaxError or ReferenceError.

+

The function accepts two parameters - the first one is the error thrown and the second, optional parameter is a "fake" error created before the handler is called so that a stack trace from before an async barrier is available. This second error is only provided if jQuery.Deferred.getErrorHook is defined; see the docs for that API for more details.

+

Example

+
+
+ + +
diff --git a/entries/jQuery.Deferred.getErrorHook.xml b/entries/jQuery.Deferred.getErrorHook.xml new file mode 100644 index 00000000..b20f98e8 --- /dev/null +++ b/entries/jQuery.Deferred.getErrorHook.xml @@ -0,0 +1,29 @@ + + + jQuery.Deferred.getErrorHook() + + 3.7 + + Return an Error instance with a defined stack. + +
+

Note: This API is not defined by default, but jQuery will make use of it when defined.

+
+

When jQuery.Deferred.getErrorHook is defined, it extends the jQuery.Deferred features added in jQuery 3.0 to include an error captured before the async barrier whenever a Deferred throws an exception. This makes it easier to find programming errors that occur inside Deferreds. You can find an example implementation you can copy-paste below, or you can use jquery-deferred-reporter plugin.

+

+jQuery.Deferred.getErrorHook = function() {
+  try {
+    throw new Error( "Exception in jQuery.Deferred" );
+  } catch ( err ) {
+    return err;
+  }
+};
+    
+

When defined, an error returned by this API is passed to jQuery.Deferred.exceptionHook as the second parameter.

+

Why does this API exist?

+

Prior to jQuery 3.0, Deferreds would simply terminate and the browser would generate a message on the console if an exception occurred such as attempting to call an undefined method as a function (e.g., myobject.missingFunction()). As of version 3.0, jQuery.Deferred follows the Promise/A+ specification when you use the .then method. The spec requires all errors to be trapped by the Promise, which prevents console errors from being logged. If the user has forgotten to add a handler for rejected promises, this can result in the error being silently swallowed with no notification at all!

+

The native Promise object as implemented in the browser tracks Promise rejections and reports problems on the console. However, doing the same type of reporting in the JavaScript world is much more difficult. jQuery itself is unable to use the native Promise because jQuery.Deferred implements a superset of Promise that requires additional features for methods like .done or .fail, and because Promise is not implemented on all the platforms that jQuery supports.

+
+ + +
diff --git a/entries/jQuery.Deferred.getStackHook.xml b/entries/jQuery.Deferred.getStackHook.xml new file mode 100644 index 00000000..87ee6138 --- /dev/null +++ b/entries/jQuery.Deferred.getStackHook.xml @@ -0,0 +1,30 @@ + + + jQuery.Deferred.getStackHook() + + 3.0 + + Return an Error instance with a defined stack. + +
+

Note: This API has been deprecated in jQuery 3.7; please use the jQuery.Deferred.getErrorHook method instead.

+
+
+

Note: This API is not defined by default, but jQuery will make use of it when defined.

+
+

See jQuery.Deferred.getErrorHook for the context why this API was created. Initially, we advised users to assign to it a function returning an error stack:

+

+jQuery.Deferred.getStackHook = function() {
+  try {
+    throw new Error( "Exception in jQuery.Deferred" );
+  } catch ( err ) {
+    return err.stack; // stack property returned here
+  }
+};
+    
+

However, when such a stack is then logged by jQuery from inside of jQuery.Deferred.exceptionHook, the browser won't apply source maps. Therefore, we changed the recommendation to return the full error object itself. To make it clearer, the API was also renamed.

+
+ + + +
diff --git a/entries/jQuery.ajax.xml b/entries/jQuery.ajax.xml index 9074388b..3afaf650 100644 --- a/entries/jQuery.ajax.xml +++ b/entries/jQuery.ajax.xml @@ -168,7 +168,7 @@ $.ajax({ } }); -

If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error (including 3xx redirect), they take the same parameters as the error callback.

+

If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error (including 3xx redirects to another domain), they take the same parameters as the error callback. 3xx redirects to the same domain are handled by the browser and are not controlled by jQuery.

@@ -338,7 +338,7 @@ jqxhr.always(function() {

If json is specified, the response is parsed using jQuery.parseJSON before being passed, as an object, to the success handler. The parsed JSON object is made available through the responseJSON property of the jqXHR object.

If script is specified, $.ajax() will execute the JavaScript that is received from the server before passing it on to the success handler as a string.

If jsonp is specified, $.ajax() will automatically append a query string parameter of (by default) callback=? to the URL. The jsonp and jsonpCallback properties of the settings passed to $.ajax() can be used to specify, respectively, the name of the query string parameter and the name of the JSONP callback function. The server should return valid JavaScript that passes the JSON response into the callback function. $.ajax() will execute the returned JavaScript, calling the JSONP callback function, before passing the JSON object contained in the response to the $.ajax() success handler.

-

For more information on JSONP, see the original post detailing its use.

+

For more information on JSONP, see the original post detailing its use.

Sending Data to the Server

By default, Ajax requests are sent using the GET HTTP method. If the POST method is required, the method can be specified by setting a value for the type option. This option affects how the contents of the data option are sent to the server. POST data will always be transmitted to the server using UTF-8 charset, per the W3C XMLHTTPRequest standard.

The data option can contain either a query string of the form key1=value1&key2=value2, or an object of the form {key1: 'value1', key2: 'value2'}. If the latter form is used, the data is converted into a query string using jQuery.param() before it is sent. This processing can be circumvented by setting processData to false. The processing might be undesirable if you wish to send an XML object to the server; in this case, change the contentType option from application/x-www-form-urlencoded to a more appropriate MIME type.

diff --git a/entries/jQuery.cssNumber.xml b/entries/jQuery.cssNumber.xml index ce5af886..c49b3c78 100644 --- a/entries/jQuery.cssNumber.xml +++ b/entries/jQuery.cssNumber.xml @@ -1,30 +1,50 @@ - + jQuery.cssNumber 1.4.3 - An object containing all CSS properties that may be used without a unit. The .css() method uses this object to see if it may append px to unitless values. + An object containing all CSS properties that may be used without a unit. Prior to jQuery 4.0, the .css() method uses this object to see if it may append px to unitless values. -

You can think about jQuery.cssNumber as a list of all CSS properties you might use without a unit. It's used by .css() to determine if it needs to add px to unitless values.

-

The keys of the jQuery.cssNumber object are camel-cased and the values are all set to true. If you want to prevent the .css() method from automatically adding the px unit for a specific CSS property, you can add an extra property to the jQuery.cssNumber object.

+
+

Note: This API has been removed in jQuery 4.0; please pass a string value with the desired units instead.

+
+

You can think about jQuery.cssNumber as a list of all CSS properties you might use without a unit. Prior to jQuery 4.0, it was used by .css() to determine if it needs to add px to unitless values.

+

The keys of the jQuery.cssNumber object are camel-cased and the values are all set to true. If you want to prevent the .css() method from automatically adding the px unit for a specific CSS property and that property is not yet a key of the jQuery.cssNumber object, you can add such an extra property:


-jQuery.cssNumber.someCSSProp = true;
+if ( jQuery.cssNumber ) {
+  jQuery.cssNumber.someCSSProp = true;
+}
     

By default the object contains the following properties:

    -
  • zIndex
  • -
  • fontWeight
  • -
  • opacity
  • -
  • zoom
  • -
  • lineHeight
  • -
  • widows (added in jQuery 1.6)
  • -
  • orphans (added in jQuery 1.6)
  • -
  • fillOpacity (added in jQuery 1.6.2)
  • -
  • columnCount (added in jQuery 1.9)
  • -
  • order (added in jQuery 1.10.2)
  • -
  • flexGrow (added in jQuery 1.11.1)
  • -
  • flexShrink (added in jQuery 1.11.1)
  • +
  • animationIterationCount (added in 1.12.0/2.2.0)
  • +
  • aspectRatio (added in 3.7.0)
  • +
  • borderImageSlice (added in 3.7.0)
  • +
  • columnCount (added in 1.9.0)
  • +
  • flexGrow (added in 1.11.1/2.1.1)
  • +
  • flexShrink (added in 1.11.1/2.1.1)
  • +
  • fontWeight (added in 1.4.3)
  • +
  • gridArea (added in 3.4.0)
  • +
  • gridColumn (added in 3.4.0)
  • +
  • gridColumnEnd (added in 3.4.0)
  • +
  • gridColumnStart (added in 3.4.0)
  • +
  • gridRow (added in 3.4.0)
  • +
  • gridRowEnd (added in 3.4.0)
  • +
  • gridRowStart (added in 3.4.0)
  • +
  • lineHeight (added in 1.4.3)
  • +
  • opacity (added in 1.4.3)
  • +
  • order (added in 1.10.2/2.0.3)
  • +
  • orphans (added in 1.6.0)
  • +
  • scale (added in 3.7.0)
  • +
  • widows (added in 1.6.0)
  • +
  • zIndex (added in 1.4.3)
  • +
  • zoom (added in 1.4.3)
  • +
  • fillOpacity (SVG-related, added in 1.6.2)
  • +
  • floodOpacity (SVG-related, added in 3.7.0)
  • +
  • stopOpacity (SVG-related, added in 3.7.0)
  • +
  • strokeMiterlimit (SVG-related, added in 3.7.0)
  • +
  • strokeOpacity (SVG-related, added in 3.7.0)
diff --git a/entries/jQuery.find.xml b/entries/jQuery.find.xml new file mode 100644 index 00000000..f7e3de43 --- /dev/null +++ b/entries/jQuery.find.xml @@ -0,0 +1,248 @@ + + + jQuery.find() + The jQuery selector engine, formerly known as Sizzle, is exposed under jQuery.find. This page describes all the APIs under jQuery.find. + + +

Note

+ +

jQuery selector engine first tries to run the passed selector — with some modifications — through native querySelectorAll, so selectors natively supported by the current browsers generally work out of the box. However, if the browser does not recognize the selector, jQuery does the whole selection on its own. Some newer selectors may not work with such a jQuery selection.

+ +

Selectors

+ +

CSS 3

+ +

jQuery supports virtually all CSS 3 Selectors, including escaped selectors (.foo\+bar), Unicode selectors, and results returned in document order. The only exceptions are those that would require additional DOM event listeners to keep track of the state of elements.

+ +

As such, the following pseudo-selectors are not supported:

+
    +
  • :hover
  • +
  • :active
  • +
  • :visited, :link
  • +
+ +

Note: These CSS3 pseudo-selectors were unsupported prior to version 1.9:

+
    +
  • :target
  • +
  • :root
  • +
  • :nth-last-child
  • +
  • :nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type
  • +
  • :lang()
  • +
+ +

Other selectors and conventions

+ +

Changes

+ +
    +
  • Full selector lists in :not(); e.g. :not(a.b), :not(div > p), :not(div, p)
  • +
  • Nested pseudo-selectors; e.g. :not(:has(div:first-child))
  • +
+ +

Additions

+ +
    +
  • [NAME!=VALUE]: Elements whose NAME attribute doesn't match the specified value. Equivalent to :not([NAME=VALUE]).
  • +
  • :contains(TEXT): Elements with textContent containing the word 'TEXT'. Case-sensitive.
  • +
  • :header: Header elements (h1, h2, h3, h4, h5, h6).
  • +
  • :parent: Elements with at least one child node (either text or an element).
  • +
  • :selected: (option) elements that are currently selected
  • +
+ +

Form Selector Additions

+ +

Note: In this context, input, button, select, and textarea are all considered to be input elements.

+ +
    +
  • :input: Input elements
  • +
  • :button: Input elements that are buttons or have type "button"
  • +
  • :checkbox, :file, :image, :password, :radio, :reset, :submit, :text: Input elements with the specified type
  • +
+ +

Positional Selector Additions

+ +

In this context, "positional" refers to an element's placement in the collection after a selection, based on document order. For example, div:first would return an array containing the first div on the page, while div:first em would target the first div on the page and select all em elements within.

+ +

Note: Positional indexes begin at zero.

+ +
    +
  • :first/:last: The first/last matching element
  • +
  • :even/:odd: Even/odd-numbered elements
  • +
  • :eq/:nth: The nth element; e.g. :eq(5) finds the 6th element
  • +
  • :lt/:gt: Elements at positions above/below the specified position
  • +
+ +

API

+ +

The jQuery Selection API consists of 3 parts:

+ + + +

Public API

+ +

jQuery.find( String selector[, DOMNode context[, Array results]] )

+ +

The main function for finding elements. Uses querySelectorAll if available.

+ +

returns (Array): All elements matching the selector

+ +

Parameters

+ +

selector: A CSS selector

+ +

context: An element, document, or document fragment to use as the context for finding elements. Defaults to document. + Note: Prior to version 2.1, document fragments were not valid here.

+ +

results: An array or an array-like object, to which jQuery will append results. For example, jQuery passes a jQuery collection. An "array-like object" is an object with a nonnegative numeric length property and a push method.

+ +

jQuery.find.matchesSelector( DOMElement element, String selector )

+ +

Uses native matchesSelector if available

+ +

returns(Boolean): Whether the given element matches the selector

+ +

Parameters

+ +

element: A DOMElement against which jQuery will test the selector

+ +

selector: A CSS selector

+ +

jQuery.find.matches( String selector, Array<DOMElement> elements )

+ +

returns(Array): Elements in the array that match the given selector

+ +

Parameters

+ +

selector: A CSS selector

+ +

elements: An array of DOMElements to filter against the specified selector

+ +

Extension API

+ +

jQuery.expr.match.NAME = RegExp

+ +

This contains the regular expressions used to parse a selector into different parts, to be used for finding and filtering. The name of each of the regular expressions should correspond to the names specified in the jQuery.expr.find and jQuery.expr.filter objects.

+ +

Finding

+ +

In order to add a new find function:

+
    +
  • A regular expression must be added to the match object.
  • +
  • A function to find must be defined.
  • +
  • "|" + NAME must be appended to the jQuery.expr.order regex.
  • +
+ +
jQuery.expr.find.NAME = function( match, context, isXML ) {}
+ +

A method for finding some elements on a page. The specified function will be called no more than once per selector.

+
    +
  • match is the array of results returned from matching the specified regex against the selector.
  • +
  • context is the DOMElement or DOMDocument from which selection will occur.
  • +
  • isXML is a boolean value indicating whether the function is currently operating within an XML document.
  • +
+ +

Filtering

+ +

In order to add a new filtering statement:

+
    +
  • A regular expression must be added to the match object.
  • +
  • A function must be added to the filter object.
  • +
  • A function may optionally be added to the preFilter object.
  • +
+ +
jQuery.expr.preFilter.NAME = function( match ) {}
+ +

An optional pre-filter function which allows filtering of the matched array against the corresponding regular expression, which will return a new matched array. This matched array will eventually be passed and flattened as arguments against the corresponding filter function. This is intended to clean up some of the repetitive processing that occurs in a filter function.

+ +
jQuery.expr.filter.NAME: function( element, match[1][, match[2], match[3], ...] ) {}
+ +

Note: match[0] will be deleted prior to being passed to a filter, and must not be used.

+ +

The arguments for a filter method are the element and the captures from the regex corresponding to this filter (indicated above by what is in the match, starting at index 1). The return result must be boolean: true if the element matches the selector, false if not.

+ +

Attributes

+ +
jQuery.expr.attrHandle.LOWERCASE_NAME = function( elem, casePreservedName, isXML ) {}
+ +

Handle an attribute which requires specialized processing (such as href, which has cross-browser issues). The return result must be the actual string value of that attribute.

+ +

Pseudo-selectors (pseudos)

+ +
jQuery.expr.pseudos.NAME = function( elem ) {}
+ +

The most common extension to a selector engine: adding a new pseudo. The return result from this function must be boolean: true if the element matches the selector, false if not.

+ +

For example, this defines a simple :fixed pseudo:

+

+var $test = jQuery( document );
+jQuery.expr.pseudos.fixed = function( elem ) {
+  $test[ 0 ] = elem;
+  return $test.css( "position" ) === "fixed";
+};
+    
+ +
jQuery.expr.createPseudo( function )
+ +

createPseudo is only required if the custom pseudo-selector accepts an argument.

+ +

Note: In jQuery 1.8 and earlier, the API for creating custom pseudos with arguments was broken. In jQuery 1.8.1+, the API is backwards-compatible. Regardless, the use of createPseudo is greatly encouraged.

+ +

Now that the parser compiles a single function containing other functions, custom pseudo-selectors with arguments are much cleaner.

+ +

For example, within jQuery, the implementation of the :not( <sub-selector> ) pseudo is very similar to:

+ +

+jQuery.expr.pseudos.not =
+  jQuery.expr.createPseudo( function( subSelector ) {
+    var matcher = jQuery.find.compile( subSelector );
+    return function( elem ) {
+      return !matcher( elem );
+    };
+  } );
+    
+ +
jQuery.expr.setFilters.LOWERCASE_NAME = function( elements, argument, not ) {}
+ +

These filters are run after a previous part of a selector has already returned results. setFilters are found from matching jQuery.expr.match.POS. When applicable, argument is expected to be an integer. The not argument is a boolean indicating whether the result should be inverted (as in div:not(:first)).

+ +

For example, the code for the :first setFilter is similar to:

+

+var first = function( elements, argument, not ) {
+  // No argument for first
+  return not ? elements.slice( 1 ) : [ elements[ 0 ] ];
+};
+jQuery.expr.setFilters.first = first;
+    
+ +

It is easy to extend jQuery selection engine — even jQuery's POS selectors. For example, to rename :first as :uno:

+
+ +

Internal API

+ +

Note: Functionality should be accessed via the Public and Extension APIs. While the Internal API is intended specifically for internal use, it has been exposed for edge cases.

+ +

jQuery.expr.cacheLength

+ +

jQuery internally caches compiled selector functions and tokenization objects. The length of these caches defaults to 50, but can be set to any positive integer by assigning to this property.

+ +

jQuery.find.compile( selector )

+ +

This method compiles a selector function and caches it for later use. For example, calling jQuery.find.compile( ".myWidget:myPseudo" ) during initialization of a plugin will speed up the first selection of matching elements.

+ +

returns(Function): The compiled function to be used when filtering the set of possibly matching elements

+ +

Parameters

+ +

selector: A CSS selector

+ +
+
diff --git a/entries/jQuery.fx.interval.xml b/entries/jQuery.fx.interval.xml index ddcf4296..b86516c3 100644 --- a/entries/jQuery.fx.interval.xml +++ b/entries/jQuery.fx.interval.xml @@ -1,5 +1,5 @@ - + jQuery.fx.interval The rate (in milliseconds) at which animations fire. diff --git a/entries/jQuery.get.xml b/entries/jQuery.get.xml index 575a6f83..e0f7af6f 100644 --- a/entries/jQuery.get.xml +++ b/entries/jQuery.get.xml @@ -15,7 +15,7 @@ - A callback function that is executed if the request succeeds. Required if dataType is provided, but you can use null or jQuery.noop as a placeholder. + A callback function that is executed if the request succeeds. Required if dataType is provided, but you can use null or jQuery.noop as a placeholder. NOTE: In jQuery 3.x and older, when providing a null value for success you also have to provide the data parameter; you can set it to null or undefined. The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html). diff --git a/entries/jQuery.isArray.xml b/entries/jQuery.isArray.xml index 6ce958df..9891126f 100644 --- a/entries/jQuery.isArray.xml +++ b/entries/jQuery.isArray.xml @@ -1,5 +1,5 @@ - + jQuery.isArray() 1.3 diff --git a/entries/jQuery.isFunction.xml b/entries/jQuery.isFunction.xml index 3524ace2..5160f0a7 100644 --- a/entries/jQuery.isFunction.xml +++ b/entries/jQuery.isFunction.xml @@ -1,5 +1,5 @@ - + jQuery.isFunction() 1.2 diff --git a/entries/jQuery.isNumeric.xml b/entries/jQuery.isNumeric.xml index 7e64d4b7..c4fe4a72 100644 --- a/entries/jQuery.isNumeric.xml +++ b/entries/jQuery.isNumeric.xml @@ -1,5 +1,5 @@ - + jQuery.isNumeric() Determines whether its argument represents a JavaScript number. diff --git a/entries/jQuery.isWindow.xml b/entries/jQuery.isWindow.xml index e79a95a7..76a58f17 100644 --- a/entries/jQuery.isWindow.xml +++ b/entries/jQuery.isWindow.xml @@ -1,5 +1,5 @@ - + jQuery.isWindow() 1.4.3 diff --git a/entries/jQuery.now.xml b/entries/jQuery.now.xml index b482637c..00992aba 100644 --- a/entries/jQuery.now.xml +++ b/entries/jQuery.now.xml @@ -1,5 +1,5 @@ - + jQuery.now() 1.4.3 diff --git a/entries/jQuery.parseJSON.xml b/entries/jQuery.parseJSON.xml index a3249174..2023ebc8 100644 --- a/entries/jQuery.parseJSON.xml +++ b/entries/jQuery.parseJSON.xml @@ -1,5 +1,5 @@ - + diff --git a/entries/jQuery.post.xml b/entries/jQuery.post.xml index e5411bed..e862071f 100644 --- a/entries/jQuery.post.xml +++ b/entries/jQuery.post.xml @@ -15,7 +15,7 @@ - A callback function that is executed if the request succeeds. Required if dataType is provided, but can be null in that case. + A callback function that is executed if the request succeeds. Required if dataType is provided, but can be null or jQuery.noop as a placeholder. NOTE: In jQuery 3.x and older, when providing a null value for success you also have to provide the data parameter; you can set it to undefined. The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html). diff --git a/entries/jQuery.trim.xml b/entries/jQuery.trim.xml index 6732a155..cfc537b6 100644 --- a/entries/jQuery.trim.xml +++ b/entries/jQuery.trim.xml @@ -1,5 +1,5 @@ - + jQuery.trim() 1.0 diff --git a/entries/jQuery.type.xml b/entries/jQuery.type.xml index b9ce8a8e..4dd56897 100644 --- a/entries/jQuery.type.xml +++ b/entries/jQuery.type.xml @@ -1,5 +1,5 @@ - + jQuery.type() 1.4.3 diff --git a/entries/jQuery.xml b/entries/jQuery.xml index 921ca1a9..8df77906 100644 --- a/entries/jQuery.xml +++ b/entries/jQuery.xml @@ -178,12 +178,12 @@ $( myForm.elements ).hide();

By default, elements are created with an .ownerDocument matching the document into which the jQuery library was loaded. Elements being injected into a different document should be created using that document, e.g., $("<p>hello iframe</p>", $("#myiframe").prop("contentWindow").document).

If the HTML is more complex than a single tag without attributes, as it is in the above example, the actual creation of the elements is handled by the browser's .innerHTML mechanism. In most cases, jQuery creates a new <div> element and sets the innerHTML property of the element to the HTML snippet that was passed in. When the parameter has a single tag (with optional closing tag or quick-closing) — $( "<img />" ) or $( "<img>" ), $( "<a></a>" ) or $( "<a>" ) — jQuery creates the element using the native JavaScript .createElement() function.

When passing in complex HTML, some browsers may not generate a DOM that exactly replicates the HTML source provided. As mentioned, jQuery uses the browser's .innerHTML property to parse the passed HTML and insert it into the current document. During this process, some browsers filter out certain elements such as <html>, <title>, or <head> elements. As a result, the elements inserted may not be representative of the original string passed.

-

Filtering isn't, however, limited to these tags. For example, Internet Explorer prior to version 8 will also convert all href properties on links to absolute URLs, and Internet Explorer prior to version 9 will not correctly handle HTML5 elements without the addition of a separate compatibility layer.

+

Filtering isn't, however, limited to these tags. For example, Internet Explorer prior to version 8 will also convert all href properties on links to absolute URLs, and Internet Explorer prior to version 9 will not correctly handle HTML5 elements without the addition of a separate compatibility layer.

To ensure cross-platform compatibility, the snippet must be well-formed. Tags that can contain other elements should be paired with a closing tag:

$( "<a href='https://jquery.com'></a>" );

Tags that cannot contain elements may be quick-closed or not:


-$( "<img>" );
+$( "<img />" );
 $( "<input>" );
       

When passing HTML to jQuery(), note that text nodes are not treated as DOM elements. With the exception of a few methods (such as .content()), they are generally ignored or removed. E.g:

diff --git a/entries/keypress.xml b/entries/keypress.xml index 16cf4303..089765bf 100644 --- a/entries/keypress.xml +++ b/entries/keypress.xml @@ -7,8 +7,8 @@ Bind an event handler to the "keypress" event. 1.7 - - The string "keyup". + + The string "keypress". An object containing data that will be passed to the event handler. @@ -113,16 +113,16 @@ $( "#other" ).on( "click", function() {
- keyup event - Trigger the "keyup" event on an element. + keypress event + Trigger the "keypress" event on an element. 1.0 - - The string "keyup". + + The string "keypress". -

See the description for .on( "keyup", ... ).

+

See the description for .on( "keypress", ... ).

diff --git a/entries/submit-selector.xml b/entries/submit-selector.xml index f6c48b8f..43925590 100644 --- a/entries/submit-selector.xml +++ b/entries/submit-selector.xml @@ -9,7 +9,7 @@

The :submit selector typically applies to button or input elements. Note that some browsers treat <button> element as type="submit" implicitly while others (such as Internet Explorer) do not. To ensure that markup works consistently across all browsers and guarantee that it is possible to consistently select buttons that will submit a form, always specify a type property.

- + Finds all submit elements that are descendants of a td element.
@@ -44,12 +44,19 @@ elem.getAttribute( "checked" ) "checked" (String) Initial state of the checkbox; does not change"" (String) Initial state of the checkbox; does not change
+ $( elem ).attr( "checked" ) + (4.0+) + "" (String) Initial state of the checkbox; does not change
$( elem ).attr( "checked" ) - (1.6+) + (1.6-3.x) "checked" (String) Initial state of the checkbox; does not change