diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 000000000..8b808995d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+# editorconfig.org
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.js, *.xsl]
+indent_style = tab
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..b7ca95b5b
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,5 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# JS files must always use LF for tools to work
+*.js eol=lf
diff --git a/.github/configs/hydra-config.json b/.github/configs/hydra-config.json
new file mode 100644
index 000000000..2173722b4
--- /dev/null
+++ b/.github/configs/hydra-config.json
@@ -0,0 +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://api.jquery.com/wp-json/oembed/1.0/embed"
+ ]
+}
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 000000000..aa2f74565
--- /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
new file mode 100644
index 000000000..6b194c622
--- /dev/null
+++ b/.github/workflows/node.js.yml
@@ -0,0 +1,32 @@
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
+
+name: Node.js CI
+
+on:
+ pull_request:
+ push:
+ branches-ignore: "dependabot/**"
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ node-version: [18.x, 20.x]
+
+ steps:
+ - 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
new file mode 100644
index 000000000..ac635ea44
--- /dev/null
+++ b/.github/workflows/spider-check.yaml
@@ -0,0 +1,32 @@
+name: spider-check
+on:
+ # Once a week on Friday at 00:00
+ schedule:
+ - cron: '0 0 * * 5'
+ # Or manually
+ workflow_dispatch:
+ # Or when developing this workflow
+ 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
+ runs-on: ubuntu-latest
+ env:
+ # Site address to crawl
+ MY_SITE: https://api.jquery.com
+ steps:
+ - name: Checkout
+ uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
+
+ - name: Run hydra-link-checker
+ run: |
+ curl -O https://raw.githubusercontent.com/jquery/hydra-link-checker/v2.0.0/hydra.py
+ python3 hydra.py "$MY_SITE" --config .github/configs/hydra-config.json
diff --git a/.github/workflows/typesense.yaml b/.github/workflows/typesense.yaml
new file mode 100644
index 000000000..c96982758
--- /dev/null
+++ b/.github/workflows/typesense.yaml
@@ -0,0 +1,30 @@
+name: typesense
+on:
+ # Once a day at 11:30 UTC ` element) do not bubble
#### Spelling
+
* The documentation standardizes on American English spelling. For example:
* **Yes**: color, while, among, customize, argument
* **No**: colour, whilst, amongst, customise, arguement
#### Pronoun Usage
+
* Use second-person pronoun ("you") when necessary, but try to avoid it.
-* Favor the definite article ("the") over second-person possesive ("your").
+* Favor the definite article ("the") over second-person possessive ("your").
* **Yes**: Insert the paragraph after the unordered list.
* **No**: Insert your paragraph after the unordered list.
* When editing current entries, change first-person plural pronouns ("we," "our," "us") to second-person.
@@ -44,28 +42,32 @@ The `xmllint` and `xsltproc` utilities need to be in your path. If you are on Wi
* **No**: And now we have our paragraph beneath the unordered list.
#### "Voice"
+
* Prefer active voice over passive.
* **Active**: Calling `.click()` binds a click handler to the elements in the collection
* **Passive**: Click handlers are bound to elements in the collection when `.click()` is called
### Code Style
-Code in the API documentation should follow the [jQuery Core Style Guide](http://docs.jquery.com/JQuery_Core_Style_Guidelines) with the following addition and exception:
+
+Code in the API documentation should follow the [jQuery Core Style Guide](https://contribute.jquery.org/style-guide/) with the following addition:
* **Document ready syntax**: Use `$( document ).ready(function() {` instead of `$(function() {` as it's harder for new users to distinguish the difference between the latter and an IIFE.
-* **Indentation**: Core guidelines say to use tabs. In API documentation, *use 2 spaces instead*. This helps keep the line width manageable and avoid horizontal scrollbars.
#### Code within prose content (paragraphs and the like):
-* Methods: use a dot, followed by the method name, followed by parentheses: e.g. The `.focus()` method is a shortcut for `.bind('focus', handler)` in the first and second variations, and `.trigger('focus')` in the third.
+
+* Methods: use a dot, followed by the method name, followed by parentheses: e.g. The `.focus()` method is a shortcut for `.on( "focus", handler )` in the first and second variations, and `.trigger( "focus" )` in the third.
* Properties: use a dot, followed by the property name: e.g. `.length`.
* Functions: use the function name, followed by parentheses: `myFunction()`.
#### Examples
+
* Examples should indicate what the expected result will be before presenting the code. This makes code clearer and skimming easier, especially for newer coders who may not understand what is supposed to be happening from reading the code itself.
* **Yes**: Find all p elements that are children of a div element and apply a border to them.
* **No**: Find all p elements that are children of a div element.
* Make your example easy to follow with good comments so that the explanation isn't necessary.
### Rhetorical Context
+
* Subject
* The entirety of jQuery's public API
* Audience
@@ -83,5 +85,5 @@ Code in the API documentation should follow the [jQuery Core Style Guide](http:/
* Strong in English writing
* Tone
* Middle ground between formal and familiar. Err on the side of formality.
- * Authoritive
+ * Authoritative
* Tactful
diff --git a/categories.xml b/categories.xml
index fa18b86d8..0fded172e 100644
--- a/categories.xml
+++ b/categories.xml
@@ -1,18 +1,18 @@
.attr(), .html(), and .val()—also act as "getters," retrieving information from DOM elements for later use.
+ ]]>
\\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar"). The W3C CSS specification contains the complete set of rules regarding valid CSS selectors. Also useful is the blog entry by Mathias Bynens on CSS character escape sequences for identifiers.
To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar"). The W3C CSS specification contains the complete set of rules regarding valid CSS selectors. Also useful is the blog entry by Mathias Bynens on CSS character escape sequences for identifiers.
Some text but not Some text.
- Attribute values in selector expressions must follow the rules for W3C CSS selectors, in general that means anything other than a simple identifier should be surrounded by quotation marks.
+The CSS specification allows elements to be identified by their attributes. While not supported by some older browsers for the purpose of styling documents, jQuery allows you to employ them regardless of the browser being used.
+When using any of the following attribute selectors, you should account for attributes that have multiple, space-separated values. Since these selectors see attribute values as a single string, this selector, for example, $("a[rel='nofollow']"), will select <a href="example.html" rel="nofollow">Some text</a> but not <a href="example.html" rel="nofollow foe">Some text</a>.
Attribute values in selector expressions must follow the rules for W3C CSS selectors; in general, that means anything other than a valid identifier should be surrounded by quotation marks.
$('a[rel="nofollow self"]')$("a[rel='nofollow self']")$("a[rel=\"nofollow self\"]")The variation you choose is generally a matter of style or convenience.
+Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the "@" symbol from your selectors in order to make them work again.
$(selector, context) method.Given a jQuery object that represents a set of DOM elements, the .add() method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to .add() can be pretty much anything that $() accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.
Given a jQuery object that represents a set of DOM elements, the .add() method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to .add() can be pretty much anything that $() accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.
Do not assume that this method appends the elements to the existing collection in the order they are passed to the .add() method. When all elements are members of the same document, the resulting collection from .add() will be sorted in document order; that is, in order of each element's appearance in the document. If the collection consists of elements from different documents or ones not in any document, the sort order is undefined. To create a jQuery object with elements in a well-defined order and without sorting overhead, use the $(array_of_DOM_elements) signature.
The updated set of elements can be used in a following (chained) method, or assigned to a variable for later use. For example:
-
-
-$("p").add("div").addClass("widget");
-var pdiv = $("p").add("div");
-
-
+
+$( "p" ).add( "div" ).addClass( "widget" );
+var pdiv = $( "p" ).add( "div" );
+
The following will not save the added elements, because the .add() method creates a new set and leaves the original set in pdiv unchanged:
-
-var pdiv = $("p");
-pdiv.add("div"); // WRONG, pdiv will not change
-
-
+
+var pdiv = $( "p" );
+pdiv.add( "div" ); // WRONG, pdiv will not change
+
Consider a page with a simple list and a paragraph following it:
-
- <ul>
+
+<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>
-<p>a paragraph</p>
-
+<p>a paragraph</p>
+
We can select the list items and then the paragraph by using either a selector or a reference to the DOM element itself as the .add() method's argument:
- $('li').add('p').css('background-color', 'red');
-
+
+$( "li" ).add( "p" ).css( "background-color", "red" );
+
Or:
-
- $('li').add(document.getElementsByTagName('p')[0])
- .css('background-color', 'red');
-
+
+$( "li" ).add( document.getElementsByTagName( "p" )[ 0 ] )
+ .css( "background-color", "red" );
+
The result of this call is a red background behind all four elements.
Using an HTML snippet as the .add() method's argument (as in the third version), we can create additional elements on the fly and add those elements to the matched set of elements. Let's say, for example, that we want to alter the background of the list items along with a newly created paragraph:
- $('li').add('<p id="new">new paragraph</p>')
- .css('background-color', 'red');
-
+
+$( "li" ).add( "<p id='new'>new paragraph</p>" )
+ .css( "background-color", "red" );
+
Although the new paragraph has been created and its background color changed, it still does not appear on the page. To place it on the page, we could add one of the insertion methods to the chain.
As of jQuery 1.4 the results from .add() will always be returned in document order (rather than a simple concatenation).
-Note: To reverse the .add() you can use .not( elements | selector ) to remove elements from the jQuery results, or .end() to return to the selection before you added.
Note: To reverse the .add() you can use .not( elements | selector ) to remove elements from the jQuery results, or .end() to return to the selection before you added.
Added this... (notice no border)
+]]>
-
+
+
-
+
+
-
+
+
-
+
+
As described in the discussion for .end(), jQuery objects maintain an internal stack that keeps track of changes to the matched set of elements. When one of the DOM traversal methods is called, the new set of elements is pushed onto the stack. If the previous set of elements is desired as well, .addBack() can help.
Consider a page with a simple list on it:
+
+<ul>
+ <li>list item 1</li>
+ <li>list item 2</li>
+ <li class="third-item">list item 3</li>
+ <li>list item 4</li>
+ <li>list item 5</li>
+</ul>
+
+ The result of the following code is a red background behind items 3, 4 and 5:
+
+$( "li.third-item" ).nextAll().addBack()
+ .css( "background-color", "red" );
+
+ First, the initial selector locates item 3, initializing the stack with the set containing just this item. The call to .nextAll() then pushes the set of items 4 and 5 onto the stack. Finally, the .addBack() invocation merges these two sets together, creating a jQuery object that points to all three items in document order: {[<li.third-item>,<li>,<li> ]}.
.addBack() method causes the previous set of DOM elements in the traversal stack to be added to the current set. In the first example, the top stack contains the set resulting from .find("p"). In the second example, .addBack() adds the previous set of elements on the stack — in this case $("div.after-addback") — to the current set, selecting both the div and its enclosed paragraphs.
+ this refers to the current element in the set.this refers to the current element in the set.It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.
+Before jQuery version 1.12/2.2, the .addClass() method manipulated the className property of the selected elements, not the class attribute. Once the property was changed, it was the browser that updated the attribute accordingly. An implication of this behavior was that this method only worked for documents with HTML DOM semantics (e.g., not pure XML documents).
As of jQuery 1.12/2.2, this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the class attribute is used instead. So, .addClass() can be used on XML or SVG documents.
More than one class may be added at a time, separated by a space, to the set of matched elements, like so:
-$("p").addClass("myClass yourClass");
+
+$( "p" ).addClass( "myClass yourClass" );
+
This method is often used with .removeClass() to switch elements' classes from one to another, like so:
$("p").removeClass("myClass noClass").addClass("yourClass");
+
+$( "p" ).removeClass( "myClass noClass" ).addClass( "yourClass" );
+
Here, the myClass and noClass classes are removed from all paragraphs, while yourClass is added.
As of jQuery 1.4, the .addClass() method's argument can receive a function.
$("ul li:last").addClass(function(index) {
+
+$( "ul li" ).addClass(function( index ) {
return "item-" + index;
-});
- Given an unordered list with five <li> elements, this example adds the class "item-4" to the last <li>.
+});
+
+ Given an unordered list with two <li> elements, this example adds the class "item-0" to the first <li> and "item-1" to the second.
+$( "p" ).last().addClass( "selected" );
+]]>
Hello
+and
+Goodbye
+]]>