This topic contains all functions that are directly related to DOM traversal:
The relationships of elements in a DOM tree use terminology of family relationships, with the topmost elements (starting with <html>) considered “older” and the deeper nestled ones “younger” family members.
For example, the following HTML snippet:
When starting from the third <li> element (highlit in the example above), we call:
<li> item that we start from: self<li> items that are on the same level as the self item as siblings<html> element, are its ancestorsThe four methods in this category allow to traverse the DOM tree in either direction to find related elements.
The .getAncestors() method returns a list of all direct ancestor elements up to and including the <html> element. The elements are in reverse order, i.e. starting from the immediate parent element and with the <html> element as the last item in the list.
The .getSiblings() method returns a list of all sibling elements.
The .getChildren() method returns a list of all immediate children elements.
The .getDescendants() method returns a list of all descendents of the element. This includes the children, the children’s children, and so on.