Add (expr) adds the elements matching the expression to the jQuery object. This function can be used to connect the element result set that matches the two expressions respectively.
Adds more elements, matched by the given expression, to the set of matched elements. Return Value
JQuery
Parameters
Expr(String, DOMElement, Array <DOMElement>): Used to match an element and add an expression String, or to dynamically generate HTML code. If it is a String Array, multiple elements are returned.
Example
Add a new element to a group of matching elements, and the new element can match the given expression.
HTML code:
<P> Hello </p> <span> Hello Again </span>
JQuery code:
$ ("P"). add ("span ")
Result:
[<P> Hello </p>, <span> Hello Again </span>]
Dynamically generate an element and add it to the matching element.
HTML code:
<P> Hello </p>
JQuery code:
$ ("P"). add ("<span> Again </span> ")
Result:
[<P> Hello </p>, <span> Hello Again </span>]
Add one or more matching elements
HTML code:
<P> Hello </p> <span id = "a"> Hello Again </span> </p>
JQuery code:
$ ("P"). add (document. getElementById (""))
Result:
[<P> Hello </p>, <p> <span id = "a"> Hello Again </span> </p>, <span id = "a"> Hello Again </span>]
Bytes ----------------------------------------------------------------------------------------------------------------
Children ([expr]) obtains a set of elements that contain all child elements of each element in a matched element set. You can use an optional expression to filter matched child elements. Note: parents () searches for all ancestor elements, while children () considers child elements instead of all descendant elements. Get a set of elements containing all of the unique children of each of the matched set of elements. this set can be filtered with an optional expression that will cause only elements matching the selector to be collected. also note: while parents () will look at all ancestors, children () will only consider immediate child elements. return Value
JQuery
Parameters
Expr(String): (optional) expression used to filter sub-elements
Example
Find each child element in the DIV.
HTML code:
<P> Hello </p> <div> <span> Hello Again </span> </div> <p> And Again </p>
JQuery code:
$ ("Div"). children ()
Result:
[<Span> Hello Again </span>]
Find the. selected class in each div.
HTML code:
<Div> <span> Hello </span> <p class = "selected"> Hello Again </p> <p> And Again </p> </div>
JQuery code:
$ ("Div"). children (". selected ")
Result:
[<P class = "selected"> Hello Again </p>]
Bytes ----------------------------------------------------------------------------------------------------------------
Contents () searches for all child nodes (including text nodes) within the matching element ). If the element is an iframe, search for the document content Find all the child nodes inside the matched elements (including text nodes), or the content document, if the element is an iframe. Return Value
JQuery
Example
Search for all text nodes and bold them
HTML code:
<P> Hello <a href = "http://ejohn.org/"> John </a>, how are you doing? </P>
JQuery code:
$ ("P"). contents (). not ("[@ nodeType = 1]"). wrap ("<B/> ");
Result:
<P> <B> Hello </B> <a href = "http://ejohn.org/"> John </a>, <B> how are you doing? </B> </p>
Add some content to an empty frame
HTML code:
<Iframe src = "/index-blank.html" width = "300" height = "100"> </iframe>
JQuery code:
$ ("Iframe"). contents (). find ("body"). append ("I'm in an iframe! ");
Bytes ----------------------------------------------------------------------------------------------------------------
Find (expr) searches for all elements that match the specified expression. This function is a good way to find the child element of the element being processed. All searches rely on jQuery expressions. This expression can be written using the selector syntax of the CSS1-3. 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. return Value
JQuery
Parameters
Expr(String): the expression used for searching.
Example
Search for the following span element from all paragraphs. Same as $ ("p span.
HTML code:
<P> <span> Hello </span>, how are you? </P>
JQuery code:
$ ("P"). find ("span ")
Result:
[<Span> Hello </span>]
Bytes ----------------------------------------------------------------------------------------------------------------
Next ([expr]) gets a set of elements next to each element in the matched element set. This function only returns the next peer element, instead of all peer elements (nextAll can be used ). You can use an optional expression for filtering. 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 for each element, not all next siblings (nor does it return the next closest sibling ). you may provide an optional expression to filter the match. return Value
JQuery
Parameters
Expr(String): (optional) filtering expression
Example
Find the peer element next to each section.
HTML code:
<P> Hello </p> <p> Hello Again </p> <div> <span> And Again </span> </div>
JQuery code:
$ ("P"). next ()
Result:
[<P> Hello Again </p>, <div> <span> And Again </span> </div>]
Find the peer element next to each section and the class name is selected.
HTML code:
<P> Hello </p> <p class = "selected"> Hello Again </p> <div> <span> And Again </span> </div>
JQuery code:
$ ("P"). next (". selected ")
Result:
[<P class = "selected"> Hello Again </p>]
Bytes ----------------------------------------------------------------------------------------------------------------
NextAll ([expr]) searches for all elements after the current element. You can use expressions to filter data. Find all sibling elements after the current element. Use an optional expression to filter the matched set. Return Value
JQuery
Parameters
Expr(String): (optional) expression used for filtering
Example
Add a class to all elements after the first div
HTML code:
<Div> </div>
JQuery code:
$ ("Div: first"). nextAll (). addClass ("after ");
Result:
[<Div class = "after"> </div>, <div class = "after"> </div>, <div class = "after"> </div>]
Bytes ----------------------------------------------------------------------------------------------------------------
Parent ([expr]) obtains a set of elements that contain the unique parent element of all matching elements. You can use an optional expression to filter data. Get a set of elements containing the unique parents of the matched set of elements. You may use an optional expression to filter the set of parent elements that will match. Return Value
JQuery
Parameters
Expr(String): (optional) filtering expression
Example
Find the parent element of each paragraph
HTML code:
<Div> <p> Hello </p> </div>
JQuery code:
$ ("P"). parent ()
Result:
[<Div> <p> Hello </p> </div> </body>]
Find the parent element of each class named selected in the parent element of a paragraph.
HTML code:
<Div> <p> Hello </p> </div> <div class = "selected"> <p> Hello Again </p> </div>
JQuery code:
$ ("P"). parent (". selected ")
Result:
[<Div class = "selected"> <p> Hello Again </p> </div>]
Bytes ----------------------------------------------------------------------------------------------------------------
Parents ([expr]) obtains a set of elements (excluding the root element) that contain the ancestor elements of all matching elements ). You can use an optional expression to filter data. Get a set of elements containing the unique ancestors of the matched set of elements (could t for the root element). The matched elements can be filtered with an optional expression. Return Value
JQuery
Parameters
Expr(String): (optional) expression used to filter ancestor Elements
Example
Find all the ancestor elements of each span element.
HTML code:
<Html> <body> <div> <p> <span> Hello </span> </p> <span> Hello Again </span> </div> </body>
JQuery code:
$ ("Span"). parents ()
Find all the ancestor elements of the p element in each span.
JQuery code:
$ ("Span"). parents ("p ")
Bytes ----------------------------------------------------------------------------------------------------------------
Prev ([expr]) obtains a set of elements that match the previous generation element next to each element in the element set. You can use an optional expression for filtering. Only peer elements that are adjacent to each other will be matched, instead of all peer elements. Get a set of elements containing the unique previous siblings of each of the matched set of elements. use an optional expression to filter the matched set. only the immediately previous sibling is returned, not all previous siblings. return Value
JQuery
Parameters
Expr(String): (optional) the expression used to filter the previous element of the same generation.
Example
Find the first peer element next to each paragraph.
HTML code:
<P> Hello </p> <div> <span> Hello Again </span> </div> <p> And Again </p>
JQuery code:
$ ("P"). prev ()
Result:
[<Div> <span> Hello Again </span> </div>]
Find the element of the class named selected in the previous peer element next to each paragraph.
HTML code:
<Div> <span> Hello </span> </div> <p class = "selected"> Hello Again </p> <p> And Again </p>
JQuery code:
$ ("P"). prev (". selected ")
Result:
[<P class = "selected"> Hello Again </p>]
Bytes ----------------------------------------------------------------------------------------------------------------
PrevAll ([expr]) can be used to search for all peer elements before the current element. Find all sibling elements before the current element. Use an optional expression to filter the matched set. Return Value
JQuery
Parameters
Expr(String): (optional) filtering expression
Example
Add a class to all previous Divs.
HTML code:
<Div> </div>
JQuery code:
$ ("Div: last"). prevAll (). addClass ("before ");
Result:
[<Div class = "before"> </div>, <div class = "before"> </div>, <div class = "before"> </div>]
Bytes ----------------------------------------------------------------------------------------------------------------
Siblings ([expr]) obtains a set of elements that contain all unique peer elements of each element in a matched element set. You can use an optional expression for filtering. 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. Return Value
JQuery
Parameters
Expr(String): (optional) expression used to filter peer Elements
Example
Find all peer elements of each div.
HTML code:
<P> Hello </p> <div> <span> Hello Again </span> </div> <p> And Again </p>
JQuery code:
$ ("Div"). siblings ()
Result:
[<P> Hello </p>, <p> And Again </p>]
Find all peer elements of each div with the class name selected.
HTML code:
<Div> <span> Hello </span> </div> <p class = "selected"> Hello Again </p> <p> And Again </p>
JQuery code:
$ ("P"). siblings (". selected ")
Result:
[<P class = "selected"> Hello Again </p>]
Bytes ------------------------------------------------------------------------------------------------------------------------
Adding andSelf () to the previously selected elements to the current element is useful for filtering or searching the elements to be added to the previously selected elements. Add the previous selection to the current selection. Useful for traversing elements, and then adding something that was matched before the last traversion. Return Value
JQuery
Example
Select All div and internal p, and add the border class
HTML code:
<Div> <p> First Paragraph </p> <p> Second Paragraph </p> </div>
JQuery code:
$ ("Div"). find ("p"). andSelf (). addClass ("border ");
Result:
<Div class = "border"> <p class = "border"> First Paragraph </p> <p class = "border"> Second Paragraph </p> </div>
Bytes ------------------------------------------------------------------------------------------------------------------------
End () returns to the latest "destructive" operation. That is, the list of matched elements is changed to the previous state. If no destructive operation is performed before, an empty set is returned. The so-called "destructive" refers to the operation of any change to the matching jQuery element. This includes any function in Traversing that returns a jQuery object-'add', 'andself ', 'Children', 'filter', 'Find ', 'map ', 'Next', 'nextall', 'not ', 'parent', 'Parents', 'prev', 'prevall ', 'siblings 'and 'slice' -- add 'clone 'in Manipulation '. Revert the most recent 'structive' operation, changing the set of matched elements to its previous state (right before the destructive operation ). if there was no destructive operation before, an empty set is returned. A 'structive' operation is any operation that changes the set of matched jQuery elements, which means any Traversing function that returns a jQuery object-including 'add', 'andself-service ', 'Children ', 'filter', 'Find', 'map', 'Next', 'nextall', 'not', 'parent', 'Parents ', 'prev ', 'prevall', 'siblings 'and slice-plus the 'clone' function (from Manipulation ). return Value
JQuery
Example
Select All p elements, find and select span sub-elements, and then return to select p elements.
HTML code:
<P> <span> Hello </span>, how are you? </P>
JQuery code:
$ ("P"). find ("span"). end ()
Result:
[<P> <span> Hello </span> how are you? </P>]