Web Development with jQuery (2015)
Part IV. Appendices
Appendix C. Selecting, Traversing, and Filtering
Method/Property |
Description |
Return Value |
Selecting |
||
$(selector) |
Makes a selection from the document. |
jQuery |
jQuery(selector) |
An alternative name for the preceding dollar sign method. |
jQuery |
length |
The number of selected elements. |
Number |
get() |
Returns all selected elements as an array, rather than as a jQuery object. |
Array |
get(index) |
Returns a single element from the selection; the index argument is the element's position in the selection, offset from zero. |
Element |
index(subject) |
Searches the selection for the specified element and returns that element's position in the selection offset from zero. |
Number |
Traversing and Filtering |
||
add(selector) |
Adds one or more elements to the selection by virtue of an additional selector. |
jQuery |
add(elements) |
Adds one or more elements to the selection by virtue of one or more element object references. |
jQuery |
add(html) |
Adds one or more elements to the selection by virtue of an HTML fragment string that is parsed and converted into DOM element object references. |
jQuery |
add(selection) |
Adds one or more elements to the selection by virtue of an existing selection reference. |
jQuery |
add(selector, context) |
Adds one or more elements to the selection by virtue of a selector. A context provides the relative point in the document where the selector should be carried out. |
jQuery |
addBack([selector]) |
Adds a set or selection of elements to the current selection; this can optionally be filtered by a selection. |
jQuery |
andSelf() |
Adds the previous selection to the current selection. Deprecated in jQuery 1.8. |
jQuery |
children([selector]) |
Makes a selection within the context of the matched elements' children. The selector argument is optional; to select all children of all the selected elements, simply omit the selector argument. |
jQuery |
closest(selector[, context]) |
Similar to the parents() method, except this method begins with the element itself, rather than its parent, and either matches the element itself or travels up the DOM to find the right ancestor. |
jQuery |
closest(selection) |
The closest() method may also use an existing selection reference. |
jQuery |
closest(element) |
The closest() method may also use a DOM element object reference directly. |
jQuery |
contents() |
Gets children elements of each matched element, including text and comment nodes, which are normally excluded from jQuery method operations. |
jQuery |
each(function(key, value)) |
Executes a callback function for every element in a selection. |
jQuery |
$(Array).each( |
Executes a callback function for every element in an array. |
Object |
end() |
Ceases any filtering that took place and returns the current selection to its previous state. |
jQuery |
eq(index) |
Reduces a selection to a single element, where index is the number representing the element's position in the selection offset from zero. |
jQuery |
eq(-index) |
Reduces a selection to a single element, where index is a negative number representing the element's position from the last element in the selection. |
jQuery |
filter(selector) |
Removes all elements that do not match the specified selector. |
jQuery |
filter(function(index)) |
The filter() method may alternatively accept a function as its first argument, which works identically to the jQuery $.each() method. The function is executed for each item selected. |
jQuery |
filter(element) |
Filters the selection based on the JavaScript node passed in the element argument, elements that match the node remain in the selection; elements that do not match the node are dropped from the selection. One or more DOM element object references can be passed in. |
jQuery |
filter(selection) |
Filters the selection based on the jQuery object passed in the selection object (the result of a jQuery selection) argument. If elements in the selection match the jQuery object, they remain in the selection; if not, those elements are removed from the selection. |
jQuery |
find(selector) |
Makes a selection within the context of matched elements' descendants. |
jQuery |
find(selection) |
Finds element descendants using an existing selection object to match element descendants against. |
jQuery |
find(element) |
Finds element descendants using an existing DOM element object to match descendants against. |
jQuery |
first() |
Removes all elements from the selection, except the first. |
jQuery |
has(selector) |
Reduces a previous selection based on whether the selection matches the selector provided in the selector argument. |
jQuery |
has(element) |
Reduces a selection based on whether the selection matches the DOM element provided in the element argument. |
jQuery |
is(selector) |
Returns true if one or more elements match the condition specified in the selector. For example: |
Boolean |
is(function(index)) |
Returns true if the callback function returns true for one or more elements. Returns false if the callback function returns false for every item passed to the callback function. |
Boolean |
is(selection) |
Returns true if the selection matches one or more items present using an existing jQuery selection. |
Boolean |
is(elements) |
Returns true if the selection matches any of the DOM element object reference(s) provided. |
Boolean |
last() |
Removes all elements from the selection, except the last. |
jQuery |
map(function(index, element)) |
Like each(), each matched element is passed into a callback function. The return value of each callback function is used to build a new jQuery object, creating a mapping to a new array of element references. Returning the item or array of items includes it in the new array. Returning null or undefined results in no item added to the new array. |
jQuery |
$(Array).map( |
Like each(), each array item is passed into a callback function. The return value of each callback function is used to build a new array, creating a mapping to a new array. Returning the item or array of items includes it in the new array. Returning null or undefined results in no item added to the new array. |
Array |
next([selector]) |
Selects the next sibling element; the selector argument is optional. |
jQuery |
nextAll([selector]) |
Selects all subsequent sibling elements; the selector argument is optional. |
jQuery |
nextUntil([selector][, filter]) |
Selects all subsequent sibling elements up to but not including the element matched by the selector. |
jQuery |
nextUntil([element][, filter]) |
Selects all subsequent sibling elements up to but not including the element object reference provided. |
jQuery |
not(selector) |
Removes elements from the selection that match the specified selector. |
jQuery |
not(elements) |
Removes elements from the selection that match the specified DOM element object reference(s). |
jQuery |
not(function(index)) |
Removes elements from the selection based on the whether the callback function returns true or false. If the callback function returns true, the element current is excluded from the selection; if the callback function returns false, it is included in the selection. |
jQuery |
not(selection) |
Removes elements from the selection based on whether the elements in the selection match elements in the provided selection object. |
jQuery |
offsetParent() |
Gets the closest ancestor element that is positioned with position absolute, relative or fixed. |
jQuery |
parent([selector]) |
Selects all immediate parent elements; the selector argument is optional. |
jQuery |
parents([selector]) |
Selects all ancestor elements; the selector argument is optional. |
jQuery |
parentsUntil([selector][, filter]) |
Matches parent or ancestor elements up to but not including the element that matches the selector. |
jQuery |
parentsUntil([element][, filter]) |
Matches parent or ancestor elements up to but not including the element that matches the provided DOM element object reference. |
jQuery |
prev([selector]) |
Selects the previous sibling element; the selector argument is optional. |
jQuery |
prevAll([selector]) |
Selects all preceding sibling elements; the selector argument is optional. |
jQuery |
prevUntil([selector][, filter]) |
Selects all preceding sibling elements up to but not including the element matched by the selector. |
jQuery |
prevUntil([element][, filter]) |
Selects all preceding sibling elements up to but not including the element object reference provided. |
jQuery |
siblings([selector]) |
Selects all sibling elements; the selector argument is optional. |
jQuery |
slice(start[, end]) |
Selects a subset of the selection, where each index is a number representing the element's position in the selection offset from zero. |
jQuery |