Measure the test taker's knowledge about how to use traversal in jquery. The jQuery traversal function includes methods for filtering, searching, and concatenating elements.
Function Description
. Add () adds the element to the set of matching elements.
. AndSelf () adds the previous element set in the stack to the current set.
. Children () obtains all child elements matching each element in the element set.
. Closest () matches the parent element step by step from the element itself and returns the first matched ancestor element.
. Contents () obtains the child elements of each element in the matched element set, including text and comment nodes.
. Each () iterates on jQuery objects and executes functions for each matching element.
. End () ends the last filtering operation in the current chain and returns the Matching Element Set to the previous status.
. Eq () reduces the set of matching elements to the new element located in the specified index.
. Filter () reduces the set of matching elements to the new elements returned by the matching selector or matching function.
. Find () gets the descendant of each element in the current matched element set, which is filtered by the selector.
. First () reduces the set of matching elements to the first element in the set.
. Has () reduces the set of matching elements to the set of descendants containing specific elements.
. Is () checks the current Matching Element Set Based on the selector. if at least one matching element exists, true is returned.
. Last () reduces the set of matching elements to the last element in the set.
. Map () transmits each element in the current matching set to the function to generate a new jQuery object containing the returned value.
. Next () gets the peer element that matches each element in the element set.
. NextAll () obtains all peer elements after each element in the matched element set, which are filtered by selector (optional ).
. NextUntil () obtains all peer elements after each element until an element matching the selector is met.
. Not () deletes an element from the matched element set.
. OffsetParent () gets the first parent Element Used for positioning.
. Parent () gets the parent element of each element in the current matched element set, which is filtered by the selector (optional ).
. Parents () gets the ancestor elements of each element in the currently matched element set, which are filtered by selector (optional ).
. ParentsUntil () obtains the ancestor element of each element in the current matched element set until an element that matches the selector is encountered.
. Prev () is used to obtain the first peer element next to each element in the matched element set, which is filtered by the selector (optional ).
. PrevAll () is used to obtain all the peer elements before each element in the element set. The selector filters (optional ).
. PrevUntil () obtains all peer elements before each element until an element matching the selector is met.
. Siblings () is used to obtain the peer elements of all elements in the matched element set, which are filtered by selector (optional ).
. Slice () reduces the set of matching elements to a subset of the specified range.
Each usage
1. each in the array
Var arr = ["one", "two", "three", "four"]; $. each (arr, function () {alert (this) ;}); // The above each Outputs one, two, three, four var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9] $. each (arr1, function (I, item) {alert (item [0]) ;}); // In fact, arr1 is a two-dimensional array, and item is equivalent to taking every one-dimensional array, // item [0] is relative to the first value in each one-dimensional array. // The above each output is: 1 4 7 var obj = {one: 1, two: 2, three: 3, four: 4}; $. each (obj, function (I) {alert (obj [I]) ;}); // This each is more powerful and can loop through every attribute. // The output result is: 1 2 3 4
2. Traverse Dom elements