Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
jQuery Traversing refers to the process of "moving through" the DOM tree to find and select HTML elements based on their relationship to other elements.
You typically start with a selected element and then move:
This navigation through the DOM structure is called traversing.
<div>
element is the parent of <ul>
, and an ancestor of everything inside it:<div>
element contains the <ul>
as its child.<div>
, including the <ul>
, <li>
, <span>
, and <b>
, are descendants of the <div>
.<ul>
element is the parent of both <li>
elements, and a child of <div>
:<ul>
element directly holds two <li>
elements as children.<div>
.<li>
element is the parent of <span>
, a child of <ul>
, and a descendant of <div>
:<li>
element contains the <span>
as its child.<ul>
, which is in turn a descendant of the <div>
.<span>
element is a child of the left <li>
and a descendant of <ul>
and <div>
:<span>
element is inside the left <li>
, making it a direct child of the <li>
.<ul>
and <div>
.<li>
elements are siblings (they share the same parent):<li>
elements are direct children of the same <ul>
element, making them siblings.<li>
element is the parent of <b>
, a child of <ul>
, and a descendant of <div>
:<li>
element contains the <b>
as its child.<ul>
, which is in turn a descendant of the <div>
.<b>
element is a child of the right <li>
and a descendant of <ul>
and <div>
:<b>
element is inside the right <li>
, making it a child of the right <li>
.<ul>
and <div>
.jQuery makes navigating through the HTML structure (DOM) super convenient with traversal methods.
These methods let you move:
The next chapters will show us how to travel up, down and sideways in the DOM tree.