The parent() method returns the direct parent element of the selected element.
This method only traverse a single level up the DOM tree.
p (direct parent) span
The parents() method returns all ancestor elements of the selected element, all the way up to the document's root element (<html>).
You can also use an optional parameter to filter the search for ancestors.
The following example returns all ancestors of all <span> elements that are <ul> elements:
The parentsUntil() method returns all ancestor elements between two given arguments.
The following example returns all ancestor elements between a <span> and a <div> element:
The children() method returns all direct children of the selected element.
This method only traverse a single level down the DOM tree.
An optional parameter can also be used to filter the search for children.
The find() method returns descendant elements of the selected element, all the way down to the last descendant.
The following example returns all <span> elements that are descendants of <div>:
The following example returns all descendants of <div>:
The siblings() method returns all sibling elements of the selected element.
The following example returns all sibling elements of <h2>:
You can also use an optional parameter to filter the search for siblings.
The following example returns all sibling elements of <h2> that are <p> elements:
The following example returns the next sibling of <h2>:
The nextAll() method returns all next sibling elements of the selected element.
The following example returns all next sibling elements of <h2>:
The nextUntil() method returns all next sibling elements between two given arguments.
The following example returns all sibling elements between a <h2> and a <h6> element:
The prev(), prevAll() and prevUntil() methods work just like the methods above but with reverse functionality: they return previous sibling elements (traverse backwards along sibling elements in the DOM tree, instead of forward).