Selection Methods
The methods described in this section alter the set of selected elements by filtering them, adding new elements, or by using the selected elements as starting points for new selections. In jQuery 1.4 and later, jQuery selections are always sorted in document order and do not contain duplicates. See Selection Methods.
add(
sel
, [context
])add(
elts
)add(
html
)The arguments to
add()
are passed to$()
, and the resulting selection is merged with the current selection.andSelf()
Adds the previously selected set of elements (from the stack) to the selection.
children([
sel
])Selects children of the selected elements. With no argument, selects all children. With a selector, selects only matching children.
closest(
sel
, [context
])Selects the closest ancestor of each selected element that matches
sel
and is a descendant ofcontext
. Ifcontext
is omitted, thecontext
property of the jQuery object is used.contents()
Selects all children of each selected element, including text nodes and comments.
end()
Pops the internal stack, restoring the selection to the state it was in before the last selection-altering method.
eq(
idx
)Selects only the selected element with the specified index. In jQuery 1.4, negative indexes count from the end.
filter(
sel
)filter(
elts
)filter(
f
(idx
):boolean)Filter the selection so it only includes elements that also match the selector
sel
, that are included in the array-like objectelts
, or for which the predicatef
returnstrue
when invoked as a method of the element.
Get jQuery Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.