Przechodzenie - przodkowie

What is traversal?

jQuery traversal, meaning 'move', is used to 'find' (or select) HTML elements based on their relationship to other elements. Start with a selection and move along this selection until you reach the element you expect.

The following figure shows a family tree. Through jQuery traversal, you can easily move up (ancestors), down (descendants), and horizontally (siblings) in the family tree starting from the selected (current) element. This movement is called traversing the DOM.

Illustration explanation:

Przechodzenie przez drzewo DOM
  • <div> Element is the parent element of <ul> and also the ancestor of all its content.
  • <ul> Element is the parent element of <li> and also the child element of <div>.
  • The left <li> element is the parent element of <span>, the child element of <ul>, and also a descendant of <div>.
  • <span>Element is a child element of <li>, and also a descendant of <ul> and <div>.
  • The two <li> elements are siblings (having the same parent element).
  • The right <li> element is the parent element of <b>, the child element of <ul>, and also a descendant of <div>.
  • <b>Element is a child element of the right <li>, and also a descendant of <ul> and <div>.

Tip:Ancestors are father, grandfather, great-grandfather, and so on. Descendants are children, grandchildren, great-grandchildren, and so on. Siblings have the same parent.

Traverse DOM

jQuery provides various methods for traversing the DOM.

The largest category of traversal methods is tree traversal (tree-traversal).

The next chapter will explain how to move up, down, and on the same level in the DOM tree.

jQuery Traversal Reference Manual

To learn about all jQuery traversal methods, please visit our jQuery Traversal Reference Manual.