jQuery Traversal

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 (ancestor), down (descendant), and horizontally (sibling) in the family tree starting from the selected (current) element. This movement is called traversing the DOM.

Illustration Explanation:

Bilangin ang DOM Tree
  • <div>Element is the parent element of <ul>, and also the ancestor of all its content.
  • <ul>Element is the parent element of <li> element, and also the child element of <div>.
  • The left <li> element is the parent element of <span>, the child element of <ul>, and also the descendant of <div>.
  • <span>Element is the child element of <li>, and also the 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 the descendant of <div>.
  • <b>Element is the child element of the right <li>, and also the descendant of <ul> and <div>.

Tip:Ancestor is parent, grandparent, great-grandparent, and so on. Descendant is child, grandchild, great-grandchild, and so on. Sibling has 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 at 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.