End the most recent 'destructive' operation, reverting the list of matched elements back to its previous state. After an end operation, the list of matched elements will revert to the last state of matched elements.
If there was no destructive operation before, an empty set is returned.
Selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs.
<p><span>Hello</span>, how are you?</p>
$("p").find("span").end();
[ <p>...</p> ]
expr | String | An expression to search with. |
---|
Searches for all elements that match the specified expression. This method is a good way to find additional descendant elements with which to process.
All searching is done using a jQuery expression. The expression can be written using CSS 1-3 Selector syntax, or basic XPath.
Starts with all paragraphs and searches for descendant span elements, same as $("p span")
<p><span>Hello</span>, how are you?</p>
$("p").find("span");
[ <span>Hello</span> ]
expression | String | Expression(s) to search with. |
---|
Removes all elements from the set of matched elements that do not match the specified expression(s). This method is used to narrow down the results of a search.
Provide a comma-separated list of expressions to apply multiple filters at once.
Selects all paragraphs and removes those without a class "selected".
<p class="selected">Hello</p><p>How are you?</p>
$("p").filter(".selected")
[ <p class="selected">Hello</p> ]
Selects all paragraphs and removes those without class "selected" and being the first one.
<p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
$("p").filter(".selected, :first")
[ <p>Hello</p>, <p class="selected">And Again</p> ]
filter | Function | A function to use for filtering |
---|
Removes all elements from the set of matched elements that do not pass the specified filter. This method is used to narrow down the results of a search.
Remove all elements that have a child ol element
<p><ol><li>Hello</li></ol></p><p>How are you?</p>
$("p").filter(function(index) { return $("ol", this).length == 0; })
[ <p>How are you?</p> ]
el | Element | An element to remove from the set |
---|
Removes the specified Element from the set of matched elements. This method is used to remove a single Element from a jQuery object.
Removes the element with the ID "selected" from the set of all paragraphs.
<p>Hello</p><p id="selected">Hello Again</p>
$("p").not( $("#selected")[0] )
[ <p>Hello</p> ]
expr | String | An expression with which to remove matching elements |
---|
Removes elements matching the specified expression from the set of matched elements. This method is used to remove one or more elements from a jQuery object.
Removes the element with the ID "selected" from the set of all paragraphs.
<p>Hello</p><p id="selected">Hello Again</p>
$("p").not("#selected")
[ <p>Hello</p> ]
elems | jQuery | A set of elements to remove from the jQuery set of matched elements. |
---|
Removes any elements inside the array of elements from the set of matched elements. This method is used to remove one or more elements from a jQuery object.
Removes all elements that match "div p.selected" from the total set of all paragraphs.
<div><p>Hello</p><p class="selected">Hello Again</p></div>
$("p").not( $("div p.selected") )
[ <p>Hello</p> ]
expr | String | An expression whose matched elements are added |
---|
Adds more elements, matched by the given expression, to the set of matched elements.
<p>Hello</p><span>Hello Again</span>
$("p").add("span")
[ <p>Hello</p>, <span>Hello Again</span> ]
html | String | A string of HTML to create on the fly. |
---|
Adds more elements, created on the fly, to the set of matched elements.
<p>Hello</p>
$("p").add("<span>Again</span>")
[ <p>Hello</p>, <span>Again</span> ]
elements | Element|Array | One or more Elements to add |
---|
Adds one or more Elements to the set of matched elements.
<p>Hello</p><p><span id="a">Hello Again</span></p>
$("p").add( document.getElementById("a") )
[ <p>Hello</p>, <span id="a">Hello Again</span> ]
<p>Hello</p><p><form><input/><button/></form>
$("p").add( document.forms[0].elements )
[ <p>Hello</p>, <input/>, <button/> ]
expr | String | The expression with which to filter |
---|
Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.
Does return false, if no element fits or the expression is not valid.
filter(String) is used internally, therefore all rules that apply there apply here, too.
Returns true, because the parent of the input is a form element
<form><input type="checkbox" /></form>
$("input[@type='checkbox']").parent().is("form")
true
Returns false, because the parent of the input is a p element
<form><p><input type="checkbox" /></p></form>
$("input[@type='checkbox']").parent().is("form")
false
expr | String | (optional) An expression to filter the parents with |
---|
Get a set of elements containing the unique parents of the matched set of elements.
Can be filtered with an optional expressions.
Find the parent element of each paragraph.
<div><p>Hello</p><p>Hello</p></div>
$("p").parent()
[ <div><p>Hello</p><p>Hello</p></div> ]
Find the parent element of each paragraph with a class "selected".
<div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
$("p").parent(".selected")
[ <div class="selected"><p>Hello Again</p></div> ]
expr | String | (optional) An expression to filter the ancestors with |
---|
Get a set of elements containing the unique ancestors of the matched set of elements (except for the root element).
Can be filtered with an optional expressions.
Find all parent elements of each span.
<html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
$("span").parents()
[ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
Find all parent elements of each span that is a paragraph.
<html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
$("span").parents("p")
[ <p><span>Hello</span></p> ]
expr | String | (optional) An expression to filter the next Elements with |
---|
Get a set of elements containing the unique next siblings of each of the matched set of elements.
It only returns the very next sibling, not all next siblings.
Can be filtered with an optional expressions.
Find the very next sibling of each paragraph.
<p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
$("p").next()
[ <p>Hello Again</p>, <div><span>And Again</span></div> ]
Find the very next sibling of each paragraph that has a class "selected".
<p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
$("p").next(".selected")
[ <p class="selected">Hello Again</p> ]
expr | String | (optional) An expression to filter the previous Elements with |
---|
Get a set of elements containing the unique previous siblings of each of the matched set of elements.
Can be filtered with an optional expressions.
It only returns the immediately previous sibling, not all previous siblings.
Find the very previous sibling of each paragraph.
<p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
$("p").prev()
[ <div><span>Hello Again</span></div> ]
Find the very previous sibling of each paragraph that has a class "selected".
<div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
$("p").prev(".selected")
[ <div><span>Hello</span></div> ]
expr | String | (optional) An expression to filter the sibling Elements with |
---|
Get a set of elements containing all of the unique siblings of each of the matched set of elements.
Can be filtered with an optional expressions.
Find all siblings of each div.
<p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
$("div").siblings()
[ <p>Hello</p>, <p>And Again</p> ]
Find all siblings with a class "selected" of each div.
<div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
$("div").siblings(".selected")
[ <p class="selected">Hello Again</p> ]
expr | String | (optional) An expression to filter the child Elements with |
---|
Get a set of elements containing all of the unique children of each of the matched set of elements.
Can be filtered with an optional expressions.
Find all children of each div.
<p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
$("div").children()
[ <span>Hello Again</span> ]
Find all children with a class "selected" of each div.
<div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
$("div").children(".selected")
[ <p class="selected">Hello Again</p> ]
str | String | The string that will be contained within the text of an element. |
---|
Filter the set of elements to those that contain the specified text.
<p>This is just a test.</p><p>So is this</p>
$("p").contains("test")
[ <p>This is just a test.</p> ]
elem | Element | The element to find the ancestors of. |
---|
All ancestors of a given element.
cur | DOMElement | The element to search from. |
---|---|---|
num | String|Number | The Nth result to match. Can be a number or a string (like 'even' or 'odd'). |
dir | String | The direction to move in (pass in something like 'previousSibling' or 'nextSibling'). |
A handy, and fast, way to traverse in a particular direction and find a specific element.
elem | Element | The element to find all the siblings of (including itself). |
---|
All elements on a specified axis.