JQuery basics (2)

Fourth, JQuery traversal
  Concept: roughly means that starting from the current element, you can find its parent and child elements.

  1. Traversal - Ancestors

    parent() - returns the parent of the selected element.

    parents() - Returns the parent element of the selected element, the parent element of the parent element.. to the top level.

    parents("ul") - Returns the parent element of the <ul> tag of the selected element, excluding sibling elements.

    parentsUntil("div") - Returns all ancestor elements between the selected element and the <div> parent element.

  2. Traverse - descendants

    children() - Returns all direct children of the selected element, excluding grandchildren.

    You can also use an optional parameter (selector) to filter the search for child elements, only child elements can be selected.

    children("#1") - Returns the child element whose id is "1" of the selected element, but the value of using the id selector is not high, it is recommended to use the .class selector.

    find(selector) - Unlike the child method, it returns all descendant elements.

  3. Traverse - Siblings (Brothers)

    siblings() - returns all siblings of the selected element, optional logarithm (selector), same as above.

    next() - Returns the next sibling of the selected element, this method returns only one element.

    nextAll() - Returns all next siblings of the selected element, not including the previous one.

    nextUntil("h6") - Similar to parentUntil(), returns all sibling elements between the selected element and <h6> sibling elements.

    Even if there is a method to select the next element, there is a method to provide the previous selected element: prev (), prevAll(), prevUntil(), the specific usage is the same as above.

  4. Traverse - transition

    first() - returns the first element of the selected element, which means that if there are multiple selected sibling elements, he will select the first sibling element, which is the current element.

    last() - Returns the last sibling of the selected element.

    eq(index) - returns the selected element with the specified index number, the index start at zero.

    filter (selector) - allows you to specify a criterion. Elements that do not match this criterion are removed from the collection, and matching elements are returned.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325218220&siteId=291194637